Support

Account

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(). ?>