ACF Custom Post Filtering Code
Use the Code to enable filitering option on custom post type:
function my_pre_get_posts( $query ) {
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
// only modify queries for 'event' post type
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'event' ) {
// allow the url to alter the query
if( isset($_GET['event_area']) ) {
$query->set('meta_key', 'event_area');
$query->set('meta_value', $_GET['event_area']);
}
}
// return
return $query;
}
// do not modify queries in the admin
if( is_admin() ) {
return $query;
}
// only modify queries for 'event' post type
if( isset($query->query_vars['post_type']) && $query->query_vars['post_type'] == 'event' ) {
// allow the url to alter the query
if( isset($_GET['event_area']) ) {
$query->set('meta_key', 'event_area');
$query->set('meta_value', $_GET['event_area']);
}
}
// return
return $query;
}
Comments
Post a Comment