• I have a custom post type called “testimonials” and within that custom post type I have a checkbox called “show_on_page”. What I need to do is call two of those testimonials that have the “show on page” checkbox checked on my homepage.

    My query looks like this… but I can’t figure out how to only grab posts that have the “show_on_page” box checked.

    $args = array ( 'post_type' => 'testimonials', 'posts_per_page' => 2, 'orderby' => 'RAND' );
    	$custom_query = new WP_Query( $args );
    	if ( $custom_query->have_posts() ):
    	while ( $custom_query->have_posts() ) :
    	$custom_query->the_post();
Viewing 1 replies (of 1 total)
  • The answer partly depends on how the checkbox is created and how the data is stored in the database. Look in the postmeta table for meta_key = ‘show_on_page’ and see what values are stored when the box is checked.

    Then add the ‘meta_key’ and ‘meta_value’ parameters to your args. If the checked value is 1, you would add this:

    'meta_key' => 'show_on_page', 'meta_value' => 1

Viewing 1 replies (of 1 total)

The topic ‘Query Custom Post Type with certain identifier’ is closed to new replies.