How to make CPTUI-Extended show posts with any of selected terms instead of all selected terms.

CPTUI-Extended offers the ability to select terms from multiple taxonomies when setting up some layouts. When you choose terms from multiple taxonomies, the results will only have posts that have each terms. That may be what you want, but what if it is not? What if you want a list of results that have any of the selected terms, but not all?

If you want to change this behavior, add the following code to your active theme’s functions.php file or a custom plugin.

<?php
function cptuiext_return_or_relation() {
    return 'OR';
}
add_filter( 'cptui_tax_query_relation', 'cptuiext_return_or_relation' );

The snippet will return the “OR” keyword to the code and will make it choose posts that have any of the terms. By default “AND” is used, making the query more restrictive.

Updated Dec 12, 2022 8:44 PM