Home › Forums › Front-end Issues › Query posts based on radio button field › Reply To: Query posts based on radio button field
Try this to query a post type to display posts based on a radio button value
<?php
// args
$args = array(
'numberposts' => -1, // Displays ALL post
'post_type' => 'custom_post_type', // Change to reflect the name of your custom post type
'meta_key' => 'custom_field', // Change to reflect the name of your custom field
'meta_value' => 'cats' // Change to reflect the name of the value in your custom field
);
// 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(); ?>
<a href="<?php the_permalink(); ?>">
<li>
<?php echo get_the_title(); ?>
</li>
</a>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.