Skip Navigation

[Resolved] can't use OR in query filters for archives

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 year, 6 months ago.

Assisted by: Waqar.

Author
Posts
#2621719

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?

#2621909

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