Support

Account

Home Forums ACF PRO Check posts for Custom Field Reply To: Check posts for Custom Field

  • Hi

    Sorry; that’s not the bit i’m stuck on.
    It’s the actual meta_query loop that doesn’t appear to be working. I’m just wondering if my ‘value’ & ‘compare’ values are correct?

    /*
    * Query posts for a true/false value.
    * This method uses the meta_query param to match the string “1” to the database value “1|0”
    */

    $posts = get_posts(array(
    	'meta_query' => array(
    		array(
    			'key' => 'field_name',
    			'value' => '1',
    			'compare' => '=='
    		)
    	)
    ));
    
    if( $posts )
    {
    	foreach( $posts as $post )
    	{
    		setup_postdata( $post );
    
    		// ...
    
    	}
    
    	wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
    }

    What should my value and compare values be?

    Thanks