Support

Account

Home Forums General Issues Get posts from checked values (checkbox) does not work Reply To: Get posts from checked values (checkbox) does not work

  • @leffdesign

    Your loop code is fine, I’ve tested it using the checkbox field inside a post. What is wrong is your ‘$args’ argument variable.

    First off, make sure the post type is correct! Secondly, the meta_key is the FIELD_NAME. make sure that is correct as well, from the looks of it, your second key name was off. Also, value => is wrong as well. don’t use %% unless that’s what the value of your checkbox is. Insert the value of your checkbox.

    It would also help if you posted a screenshot of your field group for this particular checkbox field.

    <?php $args = array(
    	'numberposts' => -1,
    	'post_type' => 'opdracht',
    	'meta_query' => array(
    		'relation' => 'OR',
    		array(
    			'key' => 'FIELD_NAME',
    			'value' => 'CHECKBOX 1 VALUE',
    			'compare' => 'LIKE'			
    		),
    		array(
    		'key' => 'FIELD_NAME',
    		'value' => 'CHECKBOX 2 VALUE',
    		'compare' => 'LIKE'	
    	)
    )
    );
     
    // get results
    $the_query = new WP_Query( $args );
     
    // The Loop
    ?>
    <?php if( $the_query->have_posts() ): ?>
    	<ul>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<li>
    			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?php endif; ?>
    
    <?php wp_reset_query(); ?>