Home › Forums › Feedback › Using pre_get_posts to filter only posts that include all values › Reply To: Using pre_get_posts to filter only posts that include all values
Hi @matteoc5,
I have some type of code for the custom post type, but it is not working can you please help? No order found.
`
function citywise_post_filter( $query ) {
if( !$query->is_main_query() ) return;
if(isset(wp_get_current_user()->roles[0]) && wp_get_current_user()->roles[0] == ‘order_manager’){
$user_id = get_current_user_id();
$zip_code = esc_attr( get_the_author_meta( ‘zip_codes’, $user_id ) );
$meta_query = $query->get(“meta_query”);
$meta_query = array(
“relation” => “AND”,
);
$query->set(‘post_type’, ‘shop_order’ );
foreach (explode(“,”, $zip_code) as $code) {
$meta_query[] = array(
‘key’=>’_billing_postcode’,
‘value’=>$code,
‘compare’ => ‘IN’,
);
}
$query->set(‘meta_query’, $meta_query );
}
return $query;
}
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.