如何解决Elementor Posts Extra Widget 的自定义查询
我希望有人能帮我创建我需要的查询。 我正在为 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;*/
} );
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。