I have, hopefully easy question. I have my query here, which is using ACF
<?php query_posts(array('post_type' => 'our-clients-list', 'posts_per_page' => 1, 'order' => 'DSC', 'orderby' => 'rand','paged'=> $paged)); ?>
<?php while(have_posts()) : the_post(); ?>
<?php the_field('testimonial_'); ?>
<?php endwhile; ?>
<?php wp_reset_query();?>
So there is a field in my custom post type called ‘testimonial_’ I would like to only execute query when custom field is not empty so !=” but not sure how to do that. Anyone can help or give me some hint?
I think this should work, but I am not 100% certain on the advanced meta query for “not” a null string. That isn’t normally how meta queries are used. As such, I have left the
set_transient
line commented out. I just noticed that you are trying to pull 1 random post, so you might not want to use the Transients API at all, but I think it would still be a good idea just with a shorter time limit, so I have the transient set to store for 1 hour. If not, you can always extract the query parts.Excellent reference on Advanced Meta Queries