我相信类别导致WP_Query Order By不能正常工作

时间:2019-11-15 作者:Mark Anthony

我问了一个问题,应该在哪里按字段外部链接排序,然后按价格字段排序。问题似乎是有些帖子有多个类别,似乎无法理解为什么它不按外部链接恶魔的顺序排序,然后按价格字段排序。

    $query = new WP_Query( array(
        \'post_type\'         => post,            
        \'posts_per_page\'    => -1,
        \'meta_query\'     => array(
            \'relation\' => \'AND\',
            \'price_clause\' => array(
                \'key\' => \'price\',
                \'compare\' => \'EXISTS\'
            ),
            \'external_clause\' => array(
                \'key\' => \'external_link\',
                \'compare\' => \'EXISTS\'
            )
        ),

        \'orderby\'    => array(
            \'external_clause\' => \'DESC\',
            \'price_clause\' => \'DESC\',
        ),
        \'tax_query\' => array(array(
                            \'taxonomy\' => \'category\',
                            \'field\'    => \'slug\',
                            \'terms\'    => $category,
                        ),) 
    ) );

1 个回复
SO网友:Mark Anthony

我设法解决了此问题。问题类型=>“numeric”

$query = new WP_Query( array(
        \'post_type\'         => post,            
        \'posts_per_page\'    => -1,

        \'category_name\'     => $category,


        \'meta_query\'     => array(
            \'relation\' => \'AND\',
            \'price_clause\' => array(
                \'key\' => \'price\',
                \'type\' => \'numeric\',
                \'compare\' => \'EXISTS\'
            ),
            \'external_clause\' => array(
                \'key\' => \'external_link\',
                \'compare\' => \'EXISTS\'
            )
        ),

        \'orderby\'    => array(
            \'external_clause\' => \'DESC\',
            \'price_clause\' => \'DESC\',
        ),

    ) );

相关推荐

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

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