通过自定义字段使用WP查询顺序,然后随机

时间:2019-03-18 13:49:19

标签: sql wordpress random

我正在尝试使用WP Query从数据库中获取信息。我正在尝试按menu_order来排序帖子,如果菜单顺序是相同的标准0,则帖子应该是随机的。

 SELECT   sus_wp_posts.* FROM sus_wp_posts  LEFT JOIN sus_wp_term_relationships ON (sus_wp_posts.ID = sus_wp_term_relationships.object_id) WHERE 1=1  AND (sus_wp_term_relationships.term_taxonomy_id IN (16,17,18,19,20)) AND sus_wp_posts.post_type = 'portfolio-item' AND ((sus_wp_posts.post_status = 'publish')) GROUP BY sus_wp_posts.ID ORDER BY menu_order ASC, RAND()

这可以解决问题,但是我无法通过WP_Query获得像这样的orderby参数。我这样尝试过:

 $query_array = array(
        'post_status'    => 'publish',
        'post_type'      => 'portfolio-item',
        'posts_per_page' => $params['number_of_items'],
        'orderby'        => array('menu_order', 'post_title'),
        'order'          => 'ASC'
    );

但是我得到以下输出:

SELECT   sus_wp_posts.* FROM sus_wp_posts  LEFT JOIN sus_wp_term_relationships ON (sus_wp_posts.ID = sus_wp_term_relationships.object_id) WHERE 1=1  AND ( 
  sus_wp_term_relationships.term_taxonomy_id IN (16,17,18,19,20)
) AND sus_wp_posts.post_type = 'portfolio-item' AND ((sus_wp_posts.post_status = 'publish')) GROUP BY sus_wp_posts.ID

0 个答案:

没有答案