Custom Post Type Query with Advanced Custom Field Check

Say you want to query a Custom post Type, but want to see if an Advanced Custom Field is checked, and just filter those posts. In this example, we want to show testimonials on the homepage, but only if the “Show on Homepage” custom field is checked, “yes”.

Here it is:

 'testimonials', // Custom Post Type name
	'posts_per_page' => '3',
	'meta_query' => array(
                     array(
                        'key' => 'show_on_homepage', // Custom field radio button
                        'value' => 'yes', // default set to no, so they have to check yes.
                        'compare' => '=', 
                        'type'      => 'CHAR'
                      )
                 )
);
$the_query = new WP_Query( $args ); ?>
have_posts() ) : ?>

  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    30 − = 29