Skip to content

Instantly share code, notes, and snippets.

@pickplugins
Created August 26, 2019 07:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pickplugins/dbd726ddf7bb5f0c3c4c0b6cc297ee34 to your computer and use it in GitHub Desktop.
Save pickplugins/dbd726ddf7bb5f0c3c4c0b6cc297ee34 to your computer and use it in GitHub Desktop.
Post Grid ajax query filter
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