crazyyy
4/28/2014 - 10:13 AM

WordPress: ACF: query post with TRUE / FALSE acf fields

WordPress: ACF: query post with TRUE / FALSE acf fields

<?php 
  $news_secondary_args = array(
    'post_type' => 'post',
    // Fetch two posts to go right of Primary Featured story
    'posts_per_page' => 2,
    // Query posts' meta 
    'meta_query' => array( 
      array(
        // Require post to have Featured Image
        'key' => '_thumbnail_id'
      ),
      array(
        // Key = ACF Field Name (True/False field)
        'key' => 'feature_on_news_center',
        // Value = 1, so 'True' radio button is selected 
        'value' => '1'
      ),
      array(
        // Key = ACF Field Name (Radio Button)
        'key' => 'news_placement',
        // The value selected (other options include 'primary' & 'tertiary')
        'value' => 'secondary'
      )
    )
  );

  // The Loop
  $news_secondary_query = new WP_Query( $news_secondary_args );
  while ( $news_secondary_query->have_posts() ) :
    $news_secondary_query->the_post(); 

?>

<!-- <html> -->

<?php 
    endwhile; // End Loop
    wp_reset_postdata(); // Reset post data in order to run additional loops such as this
?>