【问题标题】:Custom query for Elementor Posts Extra WidgetElementor Posts Extra Widget 的自定义查询
【发布时间】:2021-06-09 13:10:15
【问题描述】:

我希望有人可以帮助我创建我需要的查询。 我正在为 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' ] );
} );

【问题讨论】:

    标签: wordpress widget categories elementor posts


    【解决方案1】:
    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, 54 ),
                'operator' => 'AND'
            ),  
        ) ;
        $query->set('tax_query', $tax_query_values);
        /*echo "<pre>";
        echo "title<br>";
        print_r($query);
        echo "</pre>";
        die;*/
    } );
    

    【讨论】:

      猜你喜欢
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 2021-08-17
      • 2020-08-15
      • 1970-01-01
      • 1970-01-01
      • 2021-12-31
      • 2021-07-17
      相关资源
      最近更新 更多