Home Forums General Issues WP_Query based on ACF-field (Radio buttons) not working!


WP_Query based on ACF-field (Radio buttons) not working!

  • Hi there!

    I am getting all posts with the ACF radio button field “cat” with the value set as “nyhet”.
    I have tried a bunch of different stuff but cant grip the problem. If i remove the meta_query in args it gets all posts, so something is off.

    The radio button field only stores one value, not multiselect. And it outputs the correct value insead the while loop aswell…

    Here is the code:

    $args = array(
    	'numberposts'	=> -1,
    	'post_type'		=> 'inlagg',
    	'meta_query' => array(
                  'key' => 'cat',
                  'value' => 'nyhet'
    $the_query = new WP_Query( $args );
    <?php if( $the_query->have_posts() ): ?>
    	<?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			<a href="<?php the_permalink(); ?>">
    				<?php the_title(); ?>
    				<?php the_field('cat');?>
    	<?php endwhile; ?>
    <?php endif; ?>
    <?php wp_reset_query();?>
  • A couple of things, if you want multi-select then you have to use Checkbox, Radio Buttons are never multi-select.

    It looks like you need to get_post before you call your query. If you visit the Checkbox documentation and review the Query Posts section you will see the code you need.

  • I didnt want multiselect. Everything worked out in the end. Added 'suppress_filters' => true, and it solved it!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.