Support

Account

Home Forums Front-end Issues Show All Posts with True on True/False Field Reply To: Show All Posts with True on True/False Field

  • The query should look like this, I’ve separated the arguments from the function so that they are easier to see.

    
    $args = array(
      'post_type' => 'events',
      'posts_per_page' => -1,
      'meta_query' => array(
        array(
          'key' => 'signature_event',
          'value' => 'signature_event',
          'compare' => '==' // not really needed, this is the default
        )
      )
    );
    $the_query = new WP_Query($args);
    if ($the_query->have_posts()) {
      // This
      // if( get_field('signature_event') )
      // isn't needed since we did a query to only get ones
      // with a true value
     ?>
        <ul>
          <?php 
            while ($the_query->have_posts()) {
              $the_query->the_post();
              ?>
                <li><a href="<?php page_link(); ?>"><?php the_title(); ?></a></li>
              <?php 
            } // end while have posts
          ?>
        </ul>
      <?php
      wp_reset_postdata();
    } // end if have posts