admin管理员组

文章数量:1386695

I have custom post type 'movies' listing which i want to order by title, descending. Currently it sorts by post id. The code is:

<?php 
                        if( $movies->have_posts() ) : while( $movies->have_posts() ) : $movies->the_post();
                        $post_id = get_the_ID();
                        $the_movie = TMDB()->get_movie_details( $post_id );
                    ?>

I tried adding several things, like:

<?php 
    query_posts(array( 
        'post_type' => 'movies',
        'orderby' => 'title' 
    ) );  
?>  

And also:

<?php query_posts($query_string . '&orderby=title&order=ASC');?>

So far without succes. I am missing something. Who can help a php newbie out here?

I have custom post type 'movies' listing which i want to order by title, descending. Currently it sorts by post id. The code is:

<?php 
                        if( $movies->have_posts() ) : while( $movies->have_posts() ) : $movies->the_post();
                        $post_id = get_the_ID();
                        $the_movie = TMDB()->get_movie_details( $post_id );
                    ?>

I tried adding several things, like:

<?php 
    query_posts(array( 
        'post_type' => 'movies',
        'orderby' => 'title' 
    ) );  
?>  

And also:

<?php query_posts($query_string . '&orderby=title&order=ASC');?>

So far without succes. I am missing something. Who can help a php newbie out here?

Share Improve this question asked Apr 16, 2020 at 12:25 njinoknjinok 11 bronze badge 5
  • Where is $movies coming from? – Jacob Peattie Commented Apr 16, 2020 at 13:10
  • That is the custom taxonomy from which i want the posts to list. – njinok Commented Apr 16, 2020 at 13:12
  • No, literally where is the variable coming from? You can't just write $movies to query posts. You must have defined it somewhere? – Jacob Peattie Commented Apr 16, 2020 at 13:14
  • $movies = new WP_Query( $args ); – njinok Commented Apr 16, 2020 at 13:37
  • You know what my next question is going to be, right? What’s $args? – Jacob Peattie Commented Apr 16, 2020 at 14:03
Add a comment  | 

1 Answer 1

Reset to default -2

I think the part you are just missing order. Try this:

'post_type' => 'movies',
'orderby' => 'title',
'order'   => 'ASC',

本文标签: wp queryhaveposts order by title descending