问题描述
我希望有人能帮我创建我需要的查询。 我正在为 elementor extras 小部件引用此文档,“posts extra”:https://developers.elementor.com/custom-query-filter/
现在,我可以在编辑器中设置查询以显示来自多个类别的帖子。问题是,查询显示来自“红色”或“蓝色”的帖子。我需要查询来显示标记为“红色”和“蓝色”的帖子。
我正在使用自定义帖子类型和自定义类别,这从示例中似乎很有意义,但不起作用。我对 PHP 的了解可能在语法中的某处禁止我,但我可能会偏离:
// Showing posts in multiple categories with Posts Extra Widget
add_action( 'elementor/query/combined_categories',function( $query ) {
$query->set( 'custom_post_type',[ 'category-one' && 'category-two' ] );
} );
解决方法
add_action( 'elementor/query/custom_query_id',function( $query ) {
//$query->set( array( 'category__and' => array( 45,54 ) ) );
/*$args = array(
'post_type' => 'custom_post_type','tax_query' => array(
'relation' => 'AND',array(
'taxonomy' => 'custom-categories','field' => 'term_taxonomy_id','terms' => array( 45,54 ),)
)
);*/
//$query->set( $args );
$tax_query_values = array(
array(
'taxonomy' => 'custom-categories','field' => 'term_id','terms' => array( 45,'operator' => 'AND'
),) ;
$query->set('tax_query',$tax_query_values);
/*echo "<pre>";
echo "title<br>";
print_r($query);
echo "</pre>";
die;*/
} );