WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to order my post type archive by its parents (like page list in wp-admin).

This is what i have tried, but no luck so far.

add_action( 'pre_get_posts', 'budget_archive_data' );

function budget_archive_data($query){
    $main_budget = array(3,4);

    if ( (is_post_type_archive('account') || is_post_type_archive('budget')) && $query->is_main_query() ) {     

        $query->set( 'orderby', 'parent' );
        $query->set( 'order', 'DESC' );
        $query->set( 'posts_per_page', -1 );
        $query->set( 'post__not_in', $main_budget );


The result was:

  • Post 2 whose post_parent is 0
  • Post 3 whose post_parent is 0
  • Post 6 whose parent is 0
  • Post 4 whose parent is 2
  • Post 5 whose parent is 3

Anyone can help? Thanks before.

share|improve this question
It should work - at least it looks like it should. What results do you get? Does your action fire up at all? Could you show us what SQL query does it generate? – Krzysiek Dróżdż Jul 5 '13 at 10:32
Agreed with @KrzysiekDróżdż This look it should work. "no luck so far" is not much of a bug report though. Please explain what is happening in more detail. – s_ha_dum Jul 5 '13 at 15:16
Thanks @KrzysiekDróżdż. Added the unexpected result. – ifdion Jul 9 '13 at 0:36
Hmm, so it's sorting correctly, but with wrong order? Are you sure that you have no typo in $query->set( 'order', 'DESC' ); in your code? – Krzysiek Dróżdż Jul 9 '13 at 5:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.