Home>Support>Logical query in Post Carousel Widget

Logical query in Post Carousel Widget

Hi.
I´m using the SiteOrigin Post Carousel Widget and want to make a query using logic conditionals. Is it possible? How?
Example:
I have post”A” with categories 1, 2 and 3; post”B” with categories 1 and 3; post”C” with category 2; post”D” with categories 2 and 3; and post”E” with category 3.
I want to query taxonomy category:1 AND category:3. The result should be only post”A” and post”B”, since those are the only post that satisfy both parameters.
I hope I made myself clear, since english is not my native language.
I’d appreciate any help. Thanks.

This is our free support forum. Replies can take several days. If you need fast email support, please purchase a SiteOrigin Premium license.

  1. 5 years, 8 days ago Andrew Misplon
    Hi, I Work Here

    Hi :)

    Thanks for reaching out.

    When editing the Post Carousel widget you can open the Posts query section, there you’ll see the available options for building a query. You can use the Taxonomies field in the query builder to search for the categories you’d like to add.

  2. 5 years, 4 days ago Rup3r70

    Hi. Thanks for your answer Andrew.
    I’ve been using the widget the way you recommend. But unfortunately that way of searching does not take logic conditionals. Or more probably, I don’t find how to do it.
    Consider this other example, please.
    A videos site. Netflix style. With movies, series and documentaries. Every post is a new video. Under Categories, we have Movie, Serie, Doc, Action, Comedy, Suspense, Nature, Science, New release.
    When I make a post for a new video, under Categories, I check if it’s a movie, a series or a documental. And also, its genre, and if it’s a new release.
    Then I want to query new action movies.
    Using the taxonomies for the search, when I add the categories to search, like Movies, Action and New release, I get as result, every movie (all genres), every action movie or series, and every new relase under movie, serie or docs.
    I want to search like (Movie && Action && New release) and get only the result that satisfy those three parameters only. Excluding Action Series, or Comedy Movies, or New Documentaries.
    Hope you can help me Andrew. Or anyone who knows how to, please.

  3. 5 years, 3 days ago Andrew Misplon
    Hi, I Work Here

    Thanks for your feedback. Ideally, we’d add to the Additional field 'category__and' => array(15,19), assuming 15 and 19 were the category ID’s being targetted. The Additional field doesn’t support PHP which means we can’t make use of this option.

    To change the behavior of the Post Loop widget taxonomies field from OR to AND, you can use the following:

    function so_posts_selector_and_relation( $query ) {
        if ( isset( $query['tax_query'] ) ) {
            $query['tax_query']['relation'] = 'AND';
        }
        return $query;
    }
    add_filter( 'siteorigin_widgets_posts_selector_query', 'so_posts_selector_and_relation' );

    This function can be added to a child theme functions.php file or by adding a snippet to the plugin Code Snippets. If you make use of Code Snippets, set the snippet to run on the site front-end.

    We aren’t usually able to assist at this level within our free support scope but I’ll be adding the above to our documentation soon so it’s no problem sharing it here first. Hope this helps :)

  4. 5 years, 3 days ago Rup3r70

    Thank you Andrew.
    Tonight, I will try this method. Seems possible to work.
    I’ll let you know later the result.
    Thanks again.

  5. 5 years, 3 days ago Andrew Misplon
    Hi, I Work Here

    For sure :)

  6. 5 years, 3 days ago Rup3r70

    It worked like a charm! Thank you again Andrew. That was the solution.
    Although it’s a pity that we can’t use logic conditionals for search in the taxonomy field of the post query builder.
    I hope it will be able in future versions.
    Have a great day.

  7. 5 years, 2 days ago Andrew Misplon
    Hi, I Work Here

    Glad to hear you’re making progress. I’ll be sure to pass your feedback onto the team. All the best :)

Replies on this thread are closed. Please create a new thread if you have a question, or purchase a SiteOrigin Premium license if you need one-on-one email support.

Get The Most Out of SiteOrigin with SiteOrigin Premium

Find Out More