Home>Support>Combining Multiple Categories in Post Loop Widget Not Working

Combining Multiple Categories in Post Loop Widget Not Working

Hello, I’m trying to configure a Post Loop where selected posts must have a combination of multiple categories (AND instead of OR). I have no access to code, so this should be done via the widget interface on Page Builder. I tried many different ways using the additional query parameters field, but it does not work. It should be as simple as using a ‘+’ instead of a comma to separate category id’s. Like “cat=1+2” or “category_name=A+B” or “category__and=1,2” I’ve tried all those syntaxes and many others but none of them works as expected. I hope someone can help me out here.

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 months, 14 days ago Alex S Hi, I Work Here

    Hi Guilherme.

    Unfortunately, this is only possible by using PHP as it’s not possible to change the comparison operator from OR to AND via the interface directly. You can do this by using the siteorigin_widgets_posts_selector_query filter.

    If you don’t have a method of adding PHP, please install Code Snippets. Once installed, please navigate to SnippetsAdd Newand add the following PHP:

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

    Click Save Changes & Activate.

    If you do have a method of adding PHP to your website, please add the above PHP using that method.

    Kind regards,
    Alex

  2. 5 months, 14 days ago Guilherme Tavares

    Hello Alex, thanks for the help.

    Unfortunately I don’t have access to PHP or to install new plugins in the structure I’m working on. Anyway, I’ll try a workaround, like using a certain category to mark the posts I want, but that isn’t the optimal form. I leave you with the suggestion of implementing this upgrade, like adding a radio select under the taxonomy field to choose between OR / AND relation. Or at least making the + sign work on the additional parameters field, since there already is a wp query parameter like (cat=1+2+3).

    Best regards,
    Guilherme

  3. 5 months, 14 days ago Alex S Hi, I Work Here

    Hi Guilherme,

    I’m sorry to hear that. I’ve logged your suggestion as a feature request with the rest of the team.

    Kind regards,
    Alex

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