Created
August 26, 2019 07:05
-
-
Save pickplugins/dbd726ddf7bb5f0c3c4c0b6cc297ee34 to your computer and use it in GitHub Desktop.
Post Grid ajax query filter
This file contains 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
function post_grid_filter_query_args($query_arg, $grid_id){ | |
if( isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ){ | |
$HTTP_REFERER = $_SERVER['HTTP_REFERER']; | |
$HTTP_REFERER = str_replace('https://','', $HTTP_REFERER); | |
$HTTP_REFERER = str_replace('http://','', $HTTP_REFERER); | |
$HTTP_REFERER = explode('/', $HTTP_REFERER); | |
$HTTP_REFERER = array_filter( $HTTP_REFERER); | |
$term_slug = end($HTTP_REFERER); | |
$tax_slug = prev($HTTP_REFERER); | |
$query_arg['tax_query'][] = array( | |
'taxonomy' => $tax_slug, | |
'field' => 'slug', | |
'terms' => $term_slug, | |
); | |
} | |
return $query_arg; | |
} | |
add_filter('post_grid_filter_query_args','post_grid_filter_query_args', 10, 2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment