Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

WordPress

Display on Home Page Slider checkbox

I just finished the Extending WordPress Template Functionality of the Wordpress videos and while Zac made a point earlier to add a check box for Display on homepage Slider in the custom fields of projects he never showed us how to implement this when finally did implement the slider.

Was this an oversight, otherwise what references can I read up on to know how to make this myself?

Also, on a related note was there ever a link to the WordPress project files for us to reference?

Thanks.

3 Answers

I just asked this question before realizing it was already asked a month ago. Did you ever find any solution?

I was unable to, maybe Zac Gordon can help us?

Posted the issue on stack overflow. Here's what he left out of the tut. You put this code in that $arg statement before the slider on homepage.php. It should just be 'post_type' => 'work' right now, but here's everything that should be in there.

$args = array( 'post_type' => 'work', 'meta_key' =>'display_on_homepage', 'meta_value'=>'true' );

Don't forget the commas between the different rules in there!

Quick edit to my original solution. Put '1' instead of 'true' in there and change the ACF field to be a true/false instead of a checkbox. That is what did the trick for me!

I will try this out, thanks Daniel!

Jonathan Davies
Jonathan Davies
2,162 Points

Yeah this also work perfectly, also note make sure to check if the name of 'display_on_homepage' is the same as what you have name in your ACF.

Thanks Daniel Great fix!

I actually needed the checkbox option instead of T/F for a project I was working on, so I went over to the ACF support page and there was a piece of code there that worked perfectly for me. I went ahead and plugged in the variables that Zac Gordon used in his videos. Hope this helps!!

<?php
$args = array(
'post_type' => 'work',
'meta_query' => array(
array(
'key' => 'display_on_homepage', // name of custom field
'value' => '"Yes"', // matches exactly "Yes", not just yes. This prevents a match for "acquired"
'compare' => 'LIKE',
 )
 ),
'posts_per_page' => 3,
'order' => 'DESC'
);
$the_query = new WP_Query( $args );
?>