I want to filter my posts by below taxonomy query.
这是一个插件代码。在the_posts过滤器内部,我正在使用the_posts函数。 我有4个以蓝色分类法表示的产品。它返回4个产品,然后返回商店页面中的所有产品。我该如何处理?帮帮我...
function the_posts( $posts, $query = false ){
if ( ! is_main_query() ) return $posts;
$args = array(
'post_type' => 'product',
'numberposts' => -1,
'post_status' => 'publish',
'fields' => 'ids',
'tax_query' => array( array(
'taxonomy' => 'pa_color',
'field' => 'slug',
'terms' => array('blue'),
'operator' => 'IN',
) )
)
if ( $filtered_posts = get_posts( $args ) ) {
$insert = 0;
foreach ( $filtered_posts as $filtered_post ) {
array_splice( $posts, $insert, 0, array( $filtered_post ) );
}
}
return $posts;
}