提问者:小点点

Wordpress按标题排序,改为使用菜单顺序


我想检索自定义职位,并希望按标题排序。然而,当我做了一个什么确切的SQL请求发送转储,我发现orderby是使用menu_order而不是标题

代码如下:

$args=array(
  'post_type' => 'custom_post',
  'orderby' => 'title',
  'order' => 'ASC',
  'post_status' => 'publish',
  'posts_per_page' => '-1',
);

这里是垃圾场

"SELECT wp_posts.* FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'custom_post' AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.menu_order ASC "

因此,当我检索自定义帖子时,它不是按照我希望的顺序。谢谢你的帮助


共1个答案

匿名用户

您可以创建新的WP_查询实例以获得准确的预期结果。

<?php
$args = array(
        'post_type' => 'custom_post_type',
        'order'     => 'ASC',
        'orderby'   => 'title',
    );
$my_query = new WP_Query( $args );

if( $my_query->have_posts() ) :
while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
    <div class="smal-sec">
        <h3><?php the_title();?></h3>
        <?php the_content();?>
    </div>
<?php
endwhile;
endif;
wp_reset_query();  // Restore global post data stomped by the_post().
?>

此查询将帮助您按标题显示所有帖子顺序(A)-