Home › Forums › ACF PRO › Archive.php with custom field filter (object post) › Reply To: Archive.php with custom field filter (object post)
Thank you, can not imagine what relief dates when you solve a problem that blocks an entire project like mine.
To put chronicle the complete function for this specific use.
Result on the URL of site:
my url for archive page: http://mydomain.com/newstand/?newstand_selettore_stand=3640
The function:
function my_pre_get_posts_newstand( $query ) {
// validate
if( is_admin() ) { return; }
if( !$query->is_main_query() ) { return; }
// get original meta query
$meta_query = $query->get('meta_query');
// allow the url to alter the query
// eg: http://www.website.com/events?location=melbourne
// eg: http://www.website.com/events?location=sydney
// eg http://www.luccafan/newstand/?newstand_selettore_stand=3640
if( !empty($_GET['newstand_selettore_stand']) ){
$newstand_selettore_stand = explode(',', $_GET['newstand_selettore_stand']);
if( !empty($newstand_selettore_stand) ) {
foreach( $newstand_selettore_stand as $id ) {
$meta_query[] = array(
'key' => 'newstand_selettore_stand',
'value' => $id,
'compare' => 'LIKE',
);
}
}
}// end of !empty($_GET['newstand_selettore_stand'])
// update the meta query args
$query->set('meta_query', $meta_query);
// always return
return;
}
add_action('pre_get_posts', 'my_pre_get_posts_newstand');
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.