【问题标题】:Wordpress wp_query orderby not workingWordpress wp_query orderby 不工作
【发布时间】:2017-05-11 01:42:59
【问题描述】:

我正在尝试在 wp_query 中进行排序,但是仍然使用默认设置对帖子进行排序(只是 tag__in 正在工作)。帖子的 SQL 查询如下所示:

string(379) "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (81) ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 3" 

这里是代码sn-p:

remove_all_filters('posts_orderby');
$tag = get_term_by('name', 'title_post', 'post_tag');
$args=array(
            'order'=>'ID',
            'orderby'=>'ASC',
            'tag__in' => $tag,
            'posts_per_page'=>3, // Number of related posts to display.
            'caller_get_posts'=>1
);

$my_query = new wp_query( $args );
var_dump($my_query->request);

谢谢!

【问题讨论】:

    标签: php sql wordpress


    【解决方案1】:

    我检查了你的代码,你必须传递错误的参数。

    你能检查下面的代码吗?

    错误

    'order'=>'ID',
    'orderby'=>'ASC',
    

    正确

    'order'=>'ASC',
    'orderby'=>'ID',
    

    【讨论】:

      【解决方案2】:

      好的,我切换了 order 和 orderby ... 所以,正确的参数是 'orderby'=>'ID','order'=>'ASC',

      【讨论】:

        猜你喜欢
        • 2012-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-02-08
        • 2016-06-18
        • 2016-06-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多