Home › Forums › General Issues › Featured post through true/false field
Hello there,
I was looking for a way to have a featured posts checkbox (via true/false field) on a certain category’s posts edit window. I already found http://www.advancedcustomfields.com/resources/field-types/true-false/ and a stackoverflow thread that handles exactly that, only I don’t get any output from that code which I modified to suit the true/false field. Anyone able to help me along?
The task is simple. Show the latest ‘featured’ post at the top and all other posts below, skipping the one already featured on top. This is my code I have so far, looking good, but not putting anything out as of yet.
<?php function featured() {
$featured = new WP_Query(array(
'meta_query' => array(
array(
'key' => 'featured',
'value' => '1',
'compare' => '=='
)
),
'posts_per_page' => 1
));
while ( $featured->have_posts() ) : $featured -> the_post();
$do_not_duplicate = get_the_ID(); ?>
<article class="grid_6 push_1 featured" id="post-<?php the_ID(); ?>">
<h5><?php the_title(); ?></h5>
<div class="news_date"><a href="<?php the_permalink(); ?>"><?php the_time('d.m.Y'); ?> / Weiterlesen</a></div>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('snippet'); ?></a>
</article>
<?php
endwhile;
if(have_posts()) : while (have_posts()) : the_post();
if (get_the_ID() == $do_not_duplicate) continue;
?>
<article class="grid_2 post_item" id="post-<?php the_ID(); ?>">
<h5><?php the_title(); ?></h5>
<div class="news_date"><a href="<?php the_permalink(); ?>"><?php the_time('d.m.Y'); ?> / Weiterlesen</a></div>
<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail('snippet'); ?></a>
</article>
<?php
endwhile;
endif;
} ?>
Thanks in advance ;).
Best
physalis

Hi @physalis
It is most likely that your PW_Query args do not contain a post_Type parameter.
I have a feeling that the post_Type is required to work.
Also try setting the ‘value’ to 1 instead of ‘1’ (int instead of string)
Thanks
E
The topic ‘Featured post through true/false field’ is closed to new replies.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.