Support

Account

Home Forums General Issues Get all posts that have at least one value in a group Reply To: Get all posts that have at least one value in a group

  • $my_query = new WP_Query($args));
    if($my_query->have_posts()) {
       while($my_query->have_posts()) {
          $my_query->the_post();
          /* Add all the fields your checking for here - I'm sure there is a prettier way to do this */
          if( !empty(field_1) || !empty(field_2) || !empty(field_3) || !empty(field_4) ) {
             true;
             /* Do whatever you want now */
          } else {
             /* Do Nothing? This has an empty field */
             false;
          }
       }
    }

    You can check for it when the loop it output; this way you’re not looping through every time to check each specific field, you only loop through once and don’t show it on output.