Orderby menu_order nu funcționează

21 iun. 2012, 16:56:00
Vizualizări: 24.3K
Voturi: 3

Codul meu este:

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

Dar WordPress ordonează după 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
Comentarii

Cred că nu aceasta este problema ta, dar atât showposts cât și {tax} (unde folosești 'countries') sunt învechite. Folosește în schimb posts_per_page și un tax_query.

mrwweb mrwweb
21 iun. 2012 17:28:58
Toate răspunsurile la întrebare 3
2

Folosește asta în loc. A funcționat pentru mine

'sort_column' => 'menu_order'
7 iun. 2017 20:19:08
Comentarii

Acest răspuns este cu adevărat subapreciat. A funcționat perfect

David Kooijman David Kooijman
4 iul. 2019 15:10:03

Mă bucur că a funcționat pentru tine. Mulțumesc David

Oluwaseye Oluwaseye
5 iul. 2019 18:25:39
0

În primul rând, este suppress_filters cu două P-uri.

În al doilea rând, 'countries' => 'default' nu face nimic într-o interogare normală, așa că bănuiesc că ai altceva în cod.

În al treilea rând, când fac interogarea ta cu acest cod

$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',
    ) ),
) );

Obțin acest rezultat:

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

Observă că ordonarea după menu_order este corectă.

7 sept. 2012 22:54:51
1

Cred (aș putea greși) că problema este că doar paginile au menu_order. De asemenea, când ai înregistrat post_type, ai setat 'hierarchical' => true,?

21 iun. 2012 20:45:49
Comentarii

Cât de relevant este acest lucru pentru întrebare? Te rugăm să postezi o explicație

Pieter Goosen Pieter Goosen
22 mai 2014 13:33:56