3

My code is:

$sliders = new WP_Query(array('post_type' => 'sliders', 'showposts' => '10', 'orderby' => 'menu_order', 'order' => 'ASC', 'countries'=> 'Default', 'supress_filters' => true, 'meta_query' => array(

But wordpress orderby post_date :(

 [query] => Array
    (
        [post_type] => sliders
        [showposts] => 10
        [orderby] => menu_order
        [order] => ASC
        [countries] => ES
        [supress_filters] => 1
        [meta_query] => Array
            (
                [0] => Array
                    (
                        [key] => _sectors
                        [value] => 540
                        [compare] => IN
                    )

            )

    )

[request] =>  SELECT SQL_CALC_FOUND_ROWS  wp_posts.* FROM wp_posts  INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)  JOIN wp_icl_translations t ON wp_posts.ID = t.element_id
                    AND t.element_type = 'post_sliders' JOIN wp_icl_languages l ON t.language_code=l.code AND l.active=1 WHERE 1=1  AND ( wp_term_relationships.term_taxonomy_id IN (16) ) AND wp_posts.post_type = 'sliders' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') AND ( (wp_postmeta.meta_key = '_sectors' AND CAST(wp_postmeta.meta_value AS CHAR) IN ('540')) ) AND t.language_code='es' GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10
1
  • I doubt this is your problem but both showposts and and {tax} (where you use 'countries') are deprecated. Use posts_per_page and a tax_query instead.
    – mrwweb
    Jun 21, 2012 at 14:28

3 Answers 3

6

Use this instead. It worked for me

'sort_column' => 'menu_order'
2
  • This answer is really underrated. This worked perfectly Jul 4, 2019 at 12:10
  • I'm glad it worked for you. Thanks David
    – Oluwaseye
    Jul 5, 2019 at 15:25
5

First, it's suppress_filters with two P's.

Secondly, 'countries' => 'default' doesn't do anything in a normal query, so I suspect you have something else going on code-wise.

Third, when I do your query with this code

$sliders = new WP_Query(array('post_type' => 'sliders', 
'showposts' => '10', 
'orderby' => 'menu_order', 
'order' => 'ASC', 
'countries'=> 'Default', 
'suppress_filters' => true, 
'meta_query' => array( array(
    'key' => '_sectors',
    'value' => 540,
    'compare' => 'IN',
    ) ),
) );

I get this result:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) WHERE 1=1 AND wp_posts.post_type = 'sliders' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'future' OR wp_posts.post_status = 'draft' OR wp_posts.post_status = 'pending' OR wp_posts.post_author = 1 AND wp_posts.post_status = 'private') AND ( (wp_postmeta.meta_key = '_sectors' AND CAST(wp_postmeta.meta_value AS CHAR) IN ('540')) ) GROUP BY wp_posts.ID ORDER BY wp_posts.menu_order ASC LIMIT 0, 10

Notice that the order by menu order is correct.

3

I think (could be wrong) the problem is only pages have menu_order. Also, when you registered the post_type did you set it to 'hierarchical' => true, ?

1
  • 1
    How is this relevant to the question? Please post an explanation May 22, 2014 at 10:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.