Custom keyword search not working
-
We have an archive page for a custom post type with a custom query. There is also a search field and filter options on this page, and the query gets modified based on if there are search criteria or not.
My query works perfectly fine when you initially load the archive page, and continues to work as intended when the user enters search and filtering options.
The problem is that there are issues when Relevanssi is present. This started with the “orderby” criteria specified in my query not being respected. I’ve been able to sort through most of these issues by excluding my custom post type from being indexed. This seemed to correct all of the sorting problems. The initial loading of posts is correct, and the filtering works, however now the keyword search does NOT work.
We have specified that we want to exclude the custom post type, but it seems that relevanssi is still doing something to screw up my search. When I disable the plugin everything works fine.
We would like to keep Relevanssi enabled for any other searches on the site, while at the same time allowing this custom search to function as intended. So basically, how do I make my keyword search work while leaving Relevanssi enabled.
I am including the code for my query below. Any thoughts?
`//Setup variables
$paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : 1;
$keyword_search = get_query_var( ‘keyword_search’ );
$selected_job_types = get_query_var( ‘selected_job_types’ );
$selected_regions = get_query_var( ‘selected_regions’ );// query for job postings
$order = ‘DESC’;
$orderby = ‘date’;$jobs_args = array(
‘order’ => $order,
‘orderby’ => array(
‘meta_value’ => ‘DESC’,
‘date’ => ‘DESC’
),
‘meta_key’ => ‘featured_job’,
‘post_type’ => ‘job_portal’,
‘post_status’ => ‘publish’,
‘paged’ => $paged,
‘posts_per_page’ => ’15’,
‘posts_per_archive_page’ => ’15’,
‘relevanssi’ => false,
);// Need to add meta_query so that we check expiry date which is an ACF date picker field.
$meta_query = array(
‘relation’ => ‘OR’,
array(
‘key’ => ‘deadline’,
‘value’ => ”,
‘compare’ => ‘=’
),
array(
‘key’ => ‘deadline’,
‘value’ => date(‘Ymd’),
‘type’ => ‘DATE’,
‘compare’ => ‘>=’
)
);$jobs_args[‘meta_query’] = $meta_query;
// Check if a keyword search was submitted
if( !empty( $keyword_search ) )
$jobs_args[‘s’] = $keyword_search;// Check if filtering options were selected and if so, create or add to tax_query
$tax_query = array();// Job Types filter
if( !empty( $selected_job_types ) ) ://error_log(‘Job types: ‘ . print_r($selected_job_types, true));
$tax_query[] = array(
‘taxonomy’ => ‘job_type’,
‘field’ => ‘slug’,
‘terms’ => $selected_job_types
);
endif;// Regions filter
if( !empty( $selected_regions ) ) :$tax_query[] = array(
‘taxonomy’ => ‘region’,
‘field’ => ‘slug’,
‘terms’ => $selected_regions
);
endif;if( count( $tax_query ) > 0 )
$jobs_args[‘tax_query’] = $tax_query;$jobs = new WP_Query($jobs_args);
//html and loop to display archive for this custom post type go here
- The topic ‘Custom keyword search not working’ is closed to new replies.