Home › Forums › General Issues › Query post object not working › Reply To: Query post object not working
I will keep that error_log in mind for future projects. I got it to work by including $post_id in get_field() function.
Here is the working code:
function my_post_object_query( $args, $field, $post_id ) {
$cat = get_the_category($post_id);
$sport = $cat[0]->slug;
/*
echo '<pre>';
print_r($x['class']);
echo '</pre>';
*/
$round = get_field('round',$post_id);
$division = get_field('class',$post_id);
if($round == 'prelim'):
$next_round = 'quarterfinal';
elseif($round == 'quarterfinal'):
$next_round = 'semifinal';
elseif($round == 'semifinal'):
$next_round = 'regional final';
elseif($round == 'regional final'):
$division = array('A','B','C','D');
$next_round = 'state_championship';
else:
$division = array($division,'A','B','C','D');
$next_round = array('quarterfinal','semifinal','regional final','state championship');
endif;
$args = array(
// 'meta_key' => 'game_date_2',// priority
'orderby' => 'ID',
'order' => 'ASC',
'post_status' => 'publish',
'post_type' => 'game',
'posts_per_page' => 10,
'category_name' => $sport,
'meta_query' => array('relation' => 'AND',
array(
'key' => 'playoff_game',
'value' => 1
),
array('relation' => 'OR',
array(
'key' => 'class',
'value' => $division,
),
),
array('relation' => 'OR',
array(
'key' => 'round',
'value' => $next_round,//array('quarterfinal','semifinal','regional final','state hampionship'),
),
),
),
);
return $args;
}
// filter for every field
// add_filter('acf/fields/post_object/query', 'my_post_object_query', 10, 3);
// filter for a specific field based on it's name
//add_filter('acf/fields/post_object/query/name=my_post_object', 'my_post_object_query', 10, 3);
// filter for a specific field based on it's key
add_filter('acf/fields/post_object/query/key=field_593060bd83376', 'my_post_object_query', 10, 3);
This for your help with this!
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.