0
votes

I'm hoping someone can help me create the query I need. I am referencing this documentation for the elementor extras widget, "posts extra": https://developers.elementor.com/custom-query-filter/

Right now, I can set up the query in the editor to show posts from multiple categories. The issue is, the query shows posts from "red" OR "blue". I need the query to show posts that are tagged with BOTH "red" AND "blue".

I am using a custom post type and custom categories, this is what seemed to make sense from the examples but isn't working. My knowledge of PHP is probably prohibiting me somewhere in the syntax but I could be way off:

// 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' ] );
} );
1

1 Answers

0
votes
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;*/
} );