Trying to modify the code here https://toolset.com/forums/topic/user-view-with-or-in-the-query-filter so that my archive query filter uses the OR instead of AND operator—however it doesn't work, I guess because it's an archive and not a view? How can I override the default AND for multiple query filters for archives?
Hi,
Thank you for contacting us and I'd be happy to assist.
Your observation is correct and the 'wpv_filter_query' filter works for views, but not for the WordPress Archives.
( ref: https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query )
For archives, you can use WordPress' own filter "pre_get_posts" ( ref: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts ), along with the relevant conditional tag ( ref: https://codex.wordpress.org/Conditional_Tags#A_Post_Type_Archive ).
For example:
function my_custom_function( $query ) {
// limit this function only for the front-end and post type archive for "books"
if ( !is_admin() && is_post_type_archive( 'books' ) ) {
// view the query
print_r($query);
}
}
add_action( 'pre_get_posts', 'my_custom_function' );
I hope this helps and please let me know if you need further assistance.
regards,
Waqar