How to search archive only
-
Hi there,
I am using ACF to search custom field types as follows:-
// Search Functionality // --https://distinct.dev/jobs/?job_sector=Finance&job_type=Permanent // array of filters (field key => field name) $GLOBALS['my_query_filters'] = array( 'field_1' => 'job_sector', 'field_2' => 'job_type', 'field_3' => 'job_location', 'field_4' => 'job_salary_from', 'field_5' => 'job_salary_to' ); // action add_action('pre_get_posts', 'my_pre_get_posts', 10, 1); function my_pre_get_posts( $query ) { // bail early if is in admin if( is_admin() ) { return; } // get meta query $meta_query = $query->get('meta_query'); // loop over filters foreach( $GLOBALS['my_query_filters'] as $key => $name ) { // continue if not found in url if( empty($_GET[ $name ]) ) { continue; } // get the value for this filter // eg: https://www.website.com/events?city=melbourne,sydney $value = explode(',', $_GET[ $name ]); // append meta query $meta_query[] = array( 'key' => $name, 'value' => $value, 'compare' => 'IN', ); } // update meta query $query->set('meta_query', $meta_query); }
I want to also be able to search by a keyword, I’ve tried with the ‘s’ parameter but this then changes the template that is used and shows me blog posts as well when I am wanted to show just archive posts.
Is there a way I can achieve what I am wanting?
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How to search archive only’ is closed to new replies.