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:
<?php
$args = array(
'numberposts' => -1,
'post_type' => 'inlagg',
'meta_query' => array(
array(
'key' => 'cat',
'value' => 'nyhet'
)
)
);
$the_query = new WP_Query( $args );
?>
<?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(); ?>
<?php the_field('cat');?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?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. https://www.advancedcustomfields.com/resources/checkbox/
I didnt want multiselect. Everything worked out in the end. Added 'suppress_filters' => true,
and it solved it!