• Hi everybody,

    I want to create a shortcode which retrieves the latest post from a Custom Post Type (CPT). I know the code below works, however, I now want to only retrieve the above if another field called ‘category_type’ is equal to the word apple. Is that possible? Thanks….

    function show_casestudy_category1_callbk(){
        ob_start();
        global $post;
        $args = array(
                      'post_type' => 'casestudies',
                      'showposts' => 1
                      );
    
        $query = new WP_Query($args);
    
        if($query->have_posts()):while($query->have_posts()):$query->the_post();
        echo '<div class="wrapper">';
    	$categoryinformation= get_field('category_information',$post->ID);
    	if( $categoryinformation) {
    	echo '<div> '.$categoryinformation.' </div>';
    	}
        echo '</div>';
    
        endwhile;endif;
    
        wp_reset_postdata();
    
        return ob_get_clean();
    
    }
    
    add_shortcode('show_custom_casestudy','show_casestudy_category1_callbk');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Post Type only show for 1 category’ is closed to new replies.