Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自定义帖子下拉菜单问题-wordpress_Wordpress_Custom Post Type - Fatal编程技术网

自定义帖子下拉菜单问题-wordpress

自定义帖子下拉菜单问题-wordpress,wordpress,custom-post-type,Wordpress,Custom Post Type,我尝试用这段代码在侧边栏的下拉列表中获取我的自定义帖子列表 <form action="<? bloginfo('url'); ?>" method="get"> <select name="page_id" id="page_id"> <?php global $post; $args = array( 'post_type'=>'name', 'numberposts' => -1 ); $posts = get_posts

我尝试用这段代码在侧边栏的下拉列表中获取我的自定义帖子列表

 <form action="<? bloginfo('url'); ?>" method="get">
 <select name="page_id" id="page_id">
 <?php
 global $post;
 $args = array( 'post_type'=>'name',
'numberposts' => -1
 );
 $posts = get_posts($args);
 foreach( $posts as $post ) : setup_postdata($post); ?>
                <option value="<? echo $post->ID; ?>"><?php the_title(); ?></option>
 <?php endforeach; ?>
 </select>
 <input type="submit" name="submit" value="view" />
 </form>

您可以借助javaScript。
下图将帮助您获得所需的结果。 当用户选择该选项时,页面将自动重定向到帖子

<select onchange="javascript:location.href = this.value;">
    <?php
        foreach ($posts as $post) {
            setup_postdata($post);
            echo '<option value="'.the_permalink().'" >'.the_title().' </option>';
        }
    ?>
</select> 

您可以借助javaScript。
下图将帮助您获得所需的结果。 当用户选择该选项时,页面将自动重定向到帖子

<select onchange="javascript:location.href = this.value;">
    <?php
        foreach ($posts as $post) {
            setup_postdata($post);
            echo '<option value="'.the_permalink().'" >'.the_title().' </option>';
        }
    ?>
</select> 

请试试这个

<select name="page_id" id="page_id" onChange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
    <?php
    global $post;
    $args = array( 'post_type'=>'name',
    'numberposts' => -1
    );
    $posts = get_posts($args);
    foreach( $posts as $post ) : setup_postdata($post); ?>
        <option value="<? echo get_the_permalink($post->ID); ?>"><?php the_title(); ?></option>
    <?php endforeach; ?>
    </select>

请试试这个

<select name="page_id" id="page_id" onChange="this.options[this.selectedIndex].value && (window.location = this.options[this.selectedIndex].value);">
    <?php
    global $post;
    $args = array( 'post_type'=>'name',
    'numberposts' => -1
    );
    $posts = get_posts($args);
    foreach( $posts as $post ) : setup_postdata($post); ?>
        <option value="<? echo get_the_permalink($post->ID); ?>"><?php the_title(); ?></option>
    <?php endforeach; ?>
    </select>


您好,谢谢您的帮助,但它在所有下拉列表中仅显示_标题。现在检查我已更新了代码。我忘了在标题后面加括号。谢谢你的帮助,不管怎样,上面的代码都是jogi help me。。感谢您的时间您好,谢谢您的帮助,但它在所有下拉值中仅显示_标题。现在检查我已更新了代码。我忘了在标题后面加括号。谢谢你的帮助,不管怎样,上面的代码都是jogi help me。。谢谢你的时间