
Hi Folks,
I’ve ran in to a little trouble with my slideshow loop.
Essentially I have a custom post type that has a large number of posts. Only some of these posts will have a slideshow.
The slideshow has takes 2 fields, an image and a title.
I want to loop through the posts of this custom post type that have a slideshow image and title value in the field and only show posts posts that DO have these fields available.
This is where I thought a True/False would come in useful. I have an option to set a True/False with conditional logic, if set to true slideshow image and slideshow title appear in the wordpress admin section.
My logic would be something along the lines of:
> If post is set True to having a slideshow then
> Loop through all posts that have this condition
> Output slideshow posts only
Here is what I have tried to do:
https://gist.github.com/NicholasRowe/10790188
Though no slides appear with this code.
If anyone has any better suggestions to achieving this, I’m happy to suggestions, I just thought a True/False would be the best way to filter posts that require slide fields.
Hi,
If you want to show only the posts that have a true/false checkbox checked (the checkbox that trigger the two other field on your backend).
you should restrict to these posts directly on your query
'meta_query' => array(
'post_type' => 'areas-of-focus',
array(
'key' => 'is_a_featured_area_of_focus',
'value' => '1',
'compare' => '=='
)
)
something like that should return only the posts that have the is_a_featured_area_of_focus
field set to true.
so you can get rid of if( get_field('is_a_featured_area_of_focus') ) :
and other stuff related to checking if this field is checked on the loop and just take care of the layout.
let me know how that goes