
Hi,
On my start page I have three separated loops, with an offset. Below you can see the first one. I would like to get some assistance on how I can connect to a true/false field to this code and depending on the value show or hide the post.
If the true/false field (“show-on-startpage“) is true then the post should appear on the page, if false it should not be visible.
Can someone please help me?
Thanks
/Linus
<?php query_posts(array('orderby' => 'title', 'order' => 'asc', 'showposts' => 2, 'post_parent' => 7, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
<div class="coworker col-lg-4 col-sm-6 col-md-6 col-xs-14">
<div class="coworker-wrap">
<?php the_post_thumbnail('full', array('class' => 'img-responsive')); ?>
<div class="coworker-info">
<h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
<p><?php the_field('team');?><?php if(get_field('team')) { ?><br/><?php }?><?php the_field('title'); ?></p>
</div>
</div>
</div>
<?php } ?>
<?php wp_reset_query(); ?>
There are multiple ways to do this. You could either create a custom taxonomy called something like “show_on_home” and then, just like a category, you would choose an option when publishing the post and the just add ‘show_on_home’ => ‘true’ to your query.
Or, if you really want to use ACF to do this, you could just use a conditional statement to hide some of them. Something like this:
if (get_field('show_on_home')) {
Put your loop here...
}
That is sort of inefficient though because your still loading the posts with the loop, and then just hiding them.
The better way to do it, although a bit more complex, is using meta_queries in your main query. I would start here to learn about those: http://codex.wordpress.org/Class_Reference/WP_Meta_Query