Created
October 27, 2017 11:42
-
-
Save gitSambhal/c086a59e1e080e44cfaeaf13fcbc4a09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Suggestion filter in Job listing page | |
function get_job_listing_taxonomy_on_ajax($query_args){ | |
// Get the array of the taxonomy of type job_listing_category | |
$taxonomy_array = $query_args['tax_query']; | |
if(is_array($taxonomy_array)){ | |
foreach ($taxonomy_array as $key => $ta) { | |
if($ta['taxonomy'] == 'job_listing_category' ){ | |
$cat_terms = $ta['terms']; | |
$ta_cateogory_index = $key; | |
} | |
} | |
} | |
// Now get the term id of suggestion taxonomy | |
if($cat_terms) { | |
$suggestion_terms = []; | |
foreach ($cat_terms as $key => $term_id) { | |
$result = get_term_by('id', $term_id, 'suggestion' ); | |
if($result) { | |
$suggestion_terms[] = $term_id; | |
foreach ($query_args['tax_query'][$ta_cateogory_index]['terms'] as $key => $value) { | |
if($value == $term_id){ | |
// Now delete these term ids from original job_listing_category taxonomy | |
unset($query_args['tax_query'][$ta_cateogory_index]['terms'][$key]); | |
} | |
} | |
} | |
} | |
} | |
// If the job_listing_category taxonomy array is doesn't contain any term id then remove this array | |
if(!sizeof($query_args['tax_query'][$ta_cateogory_index]['terms'])){ | |
unset($query_args['tax_query'][$ta_cateogory_index]); | |
} | |
// Now add new taxonomy array to query_args | |
if ( ! empty( $suggestion_terms ) ) { | |
$field = is_numeric( $suggestion_terms[0] ) ? 'term_id' : 'slug'; | |
$operator = 'all' === get_option( 'job_manager_category_filter_type', 'all' ) && sizeof( $suggestion_terms ) > 1 ? 'AND' : 'IN'; | |
$query_args['tax_query'][] = array( | |
'taxonomy' => 'suggestion', | |
'field' => $field, | |
'terms' => array_values( $suggestion_terms ), | |
'include_children' => $operator !== 'AND' , | |
'operator' => $operator | |
); | |
} | |
return $query_args; | |
} | |
add_filter('get_job_listings_query_args','get_job_listing_taxonomy_on_ajax'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment