Support

Account

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!