Support

Account

Home Forums Front-end Issues Querying single checkbox? Reply To: Querying single checkbox?

  • Hi Elliot, thanks for your answer. Turns out I got it completelky wrong. I was using a normal checkbox without realizing there’s a true/false checkbox that des the job just fine. However, I’m still in a bit of trouble. I have this set up:

    if(function_exists("register_field_group"))
    {
    	register_field_group(array (
    		'id' => 'acf_featured-post',
    		'title' => 'Featured Post',
    		'fields' => array (
    			array (
    				'key' => 'field_5233c482612a9',
    				'label' => 'Feature Post?',
    				'name' => 'featured',
    				'type' => 'true_false',
    				'message' => 'Is this a featured post?',
    				'default_value' => 0,
    			),
    		),
    		'location' => array (
    			array (
    				array (
    					'param' => 'post_type',
    					'operator' => '==',
    					'value' => 'post',
    					'order_no' => 0,
    					'group_no' => 0,
    				),
    			),
    		),
    		'options' => array (
    			'position' => 'side',
    			'layout' => 'default',
    			'hide_on_screen' => array (
    			),
    		),
    		'menu_order' => 0,
    	));
    }
    

    And I have no truble calling the featured posts like this:

    $posts = get_posts(array(
                            'meta_query' => array(
                                array(
                                    'key' => 'featured',
                                    'value' => '1',
                                    'compare' => '=='
                                )
                            )
                        ));
    
                    echo '<ul>';
                        if( $posts )
                        {
                            foreach( $posts as $post )
                            {
                                setup_postdata( $post );
                                echo '<li>'; the_post_thumbnail('slider'); the_title(); echo '</li>';
                            }
                        }
                    ?>
                    </ul>
    <?php wp_reset_postdata(); ?>

    However, when I use another loop like this:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
                    <h2><a href="<?php the_permalink() ;?>"><?php the_title() ;?></a></h2>
                    <?php the_post_thumbnail('home'); ?>
                    <?php the_excerpt(); ?>
    
                <?php endwhile; else: ?>
    
                    <p>Sorry, no posts to list</p>
    
                <?php endif; ?>
    
                <?php
                global $wp_query;
    
                $big = 999999999; // need an unlikely integer
    
                echo paginate_links( array(
                    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
                    'format' => '?paged=%#%',
                    'current' => max( 1, get_query_var('paged') ),
                    'total' => $wp_query->max_num_pages
                ) );
                ?>

    I’m still getting the featured posts. I don’t quite get it, shouldn’t I be getting the rest of the posts?

    Thanks a lot!