Orderby MENU_ORDER不工作

时间:2012-06-21 作者:Miquel

我的代码是:

$sliders = new WP_Query(array(\'post_type\' => \'sliders\', \'showposts\' => \'10\', \'orderby\' => \'menu_order\', \'order\' => \'ASC\', \'countries\'=> \'Default\', \'supress_filters\' => true, \'meta_query\' => array(
但wordpress orderby post\\u日期:(

 [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

3 个回复
SO网友:Oluwaseye

请改用此选项。这对我有用

\'sort_column\' => \'menu_order\'

SO网友:Otto

首先suppress_filters 有两个P。

其次,“countries”=>“default”在普通查询中没有任何作用,因此我怀疑您在代码方面还存在其他问题。

第三,当我用这个代码进行查询时

$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\',
    ) ),
) );
我得到这个结果:

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

请注意,按菜单顺序排序是正确的。

SO网友:BaltimoreDrew

我认为(可能是错误的)问题是,只有页面有menu\\u顺序。另外,当您注册post\\u类型时,是否将其设置为\'hierarchical\' => true, ?

结束

相关推荐

使用新的WP-Query()从循环中过滤后期格式;

嗨,我目前正在为我的博客构建一个主题。下面的代码指向最新的帖子(特色帖子)。因为这将有一个不同的风格比所有其他职位。然而我想过滤掉帖子格式:链接使用我在循环中定义的WP查询,因为它给我带来了更多的灵活性。我该怎么做呢? <?php $featured = new WP_Query(); $featured->query(\'showposts=1\'); ?> <?php while ($featured->have_post