dmzayasplus
dmzayasplus

Reputation: 27

Wordpress ACF Checkbox pull

So I did my due diligence looking on here for an answer since this has come up a few times in the Treehouse forum, but found nothing related. I also tried to find a related topic on the acf site but that didn't give me the right info either. Hopefully you guys can help me out.

At the end of a tutorial on Treehouse, the instructions explain to add a few custom fields using ACF. He explains how to pull all of those in the code except on one crucial one.

We are supposed to create a checkbox field with the Field Label as Display on Homepage Slider and Field Name (or slug) as display_on_homepage. The idea is that we check this on each custom post entry that we want to display on the homepage slider, if you hadn't already guessed that.

Here's the code for the slider as it stands now.

<?php get_header('header.php'); ?>
</div>
    <div id="featured" class="clearfix flexslider">
        <ul class="slides">

        <?php 

            $args = array(
                'post_type' => 'work'

            );

            $the_query = new WP_Query( $args );

        ?>

        <?php if ( have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
            <li style="background-color:<?php the_field( 'background_color' ); ?>;">
                <div class="container">
                    <div class="grid_7">
                        <img src="<?php the_field( 'homepage_slider_image' ); ?>" alt="<?php the_title(); ?> Project Screenshot">
                    </div>
                    <div id="featured-info" class="grid_5 omega">
                        <h6>Featured Work</h6>
                        <h3><?php the_title(); ?></h3>
                        <p><?php the_field( 'description' ); ?></p>
                        <p><a class="btn blue" style="background-color: <?php the_field( 'button_color' ); ?>" href="<?php the_permalink(); ?>">View Project &rarr;</a></p>
                    </div>
                </div>
            </li>
        <?php endwhile; endif; ?>
        </ul>
    </div>

I'm sure I need to pull some conditions in the args or even establish a different rule in my acf plugin, but I'm at a loss as to where to start with that can of worms. Thanks in advance for any help or advice. I'll be sure to forward this answer to the forum if I can get any assistance.

Upvotes: 0

Views: 930

Answers (2)

user2651562
user2651562

Reputation: 1

The first answer is almost there, just missing a couple of commas :)

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

Upvotes: 0

wunderdojo
wunderdojo

Reputation: 1027

You'll want to add in an argument to your query for your custom field (meta field): http://codex.wordpress.org/Class_Reference/WP_Query

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

Upvotes: 1

Related Questions