Thanks Elliot. I’ve been getting various answers on this across various forums, but nothing’s working unfortunately. Here are 2 things that I tried, per suggestions –
$args = array( 'post_type' => 'project', 'meta_query' => array('key' => 'homepage_slide', 'compare' => 'EXISTS'));
and
$args = array( 'post_type' => 'project', 'meta_query' => array('key' => 'homepage_slide', 'value' => 'true' , 'compare' => 'LIKE'));
It’s been awhile since I’ve been stumped by what started as a simple concept! I may not be thinking about this clearly…
I don’t think you have yet explained what type of field is ‘homepage_slide’.
The type of field is just an Image and I’m including it as a direct path to the image, per example –
<img src="<?php the_field('homepage_slide'); ?>" alt="slide" />
Is there a better way to do this?
It’s odd, but this still doesn’t work –
$args = array( 'post_type' => 'project', 'meta_query' => array('key' => 'homepage_slide', 'value' => '1'));
I will check out a debug plugin and see if I see anything wrong.
Just curious, if you were trying to do the same thing (add slides to a slideshow only if the homepage_slide field was completed), how would you write the query?
Unfortunately when I change it, it still loops through all projects and displays a broken image, rather than only catching projects with slideshow images:
$args = array( 'post_type' => 'project', 'meta_query' => array('meta_key' => 'homepage_slide','meta_value' => 'true'));
Hmm, looks like meta_key worked, rather than key…
Thanks Elliot. I changed to lowercase, but it’s still displaying all projects, instead of filtering for construction. Any ideas for writing the query differently?
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.