• I would like to order by post_type, but I would like to set the order. Is this possible? I have an array of post types

    $post_type = array('article', 'book', 'magazine', 'review');
    $args = array(
            'post_type' => $post_type,
    	'orderby'   => 'menu_order post_type',
    	'order'     => 'DESC',
    );
    $query = new WP_Query( $args );

    I’m not sure how the order is being determined here, as it’s returning:
    article, magazine, book, review…which is odd. Any way to set the order?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code is setting menu order first, descending. Depending on these values, the post type order may appear completely random. Only when the menu order values are the same does post type come into play. It’s also possible for other code to be altering your query so that the order is set to something else. This may be intentional or accidental. What you could try doing is hooking the “posts_request” filter and outputting the passed query string. Here you will see the actual SQL order by clause as it is used just before the query is run. Any discrepancies or alterations to your query will be evident. Based on what you find here, you can work backwards to determine where things had gone wrong.

Viewing 1 replies (of 1 total)
  • The topic ‘WP_Query: orderby post_type (set order)’ is closed to new replies.