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.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.