当tax_query在自定义分类上处于活动状态时,Wordpress不按自定义字段排序

时间:2016-11-22 15:35:59

标签: php wordpress advanced-custom-fields

我必须按价格对产品进行分类。我正忙着完成这项任务,因为我的查询仅在任何自定义分类法查询关闭时才有效。这是有效的查询,但它不会按特定的product_category过滤帖子:

$args = array(
    'post_type' => 'product',
    'paged'     => $paged,
    'orderby'   => 'meta_value_num',
    'meta_key'  => 'price',
    'order'     => 'DESC',
);

现在这段代码:

$args = array(
    'post_type'  => 'product',
    'paged'      => $paged,
    'orderby'    => 'meta_value_num',
    'meta_key'   => 'price',
    'order'      => 'DESC',
    'tax_query'  => array(
        array(
            'taxonomy' => 'product_category',
            'field'    => 'slug',
            'terms'    => $queried_slug
        )
    )
);

它查询正确的类别,但根本不进行排序。 我不确定这是怎么回事。

这是环境:
Wordpress:4.4.2
自定义字段管理与“高级自定义字段”
使用“类型”自定义帖子类型和分类

这是生成的SQL:

SELECT SQL_CALC_FOUND_ROWS  wp_posts.ID FROM wp_posts
LEFT 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 )
LEFT JOIN wp_postmeta sort ON (wp_posts.ID = sort.post_id AND sort.meta_key = 'sort_487')
WHERE 1=1
AND ( 
  wp_term_relationships.term_taxonomy_id IN (487)
)
AND ( 
  wp_postmeta.meta_key = 'price'
)
AND wp_posts.post_type = 'product'
AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'acf-disabled' OR wp_posts.post_status = 'private')
AND ( sort.meta_key = 'sort_487' OR sort.post_id IS NULL )
GROUP BY wp_posts.ID
ORDER BY CAST(sort.meta_value AS SIGNED), wp_posts.post_date DESC LIMIT 0, 18

0 个答案:

没有答案