wp_query not returning posts
-
I’m having trouble getting a shortcode to display custom post types. My shortcode returns ‘Not Found’ even if I leave the query as vague as just entering the post_type and posts_per_page arguments. What am I missing?
Here is my shortcode :
// shortcode to display simple CPT block function cpt_type_query($atts, $content = null){ extract(shortcode_atts(array( 'posts_per_page' => '5', 'post_type' => 'cpt_type' ), $atts)); global $post; $posts = new WP_Query($atts); $out = '<p><i>Not Found</i></p>'; if ($posts->have_posts()) while ($posts->have_posts()): $posts->the_post(); $out = '<div class="sf-result-item"> <a href="'.get_permalink().'"> <h2>'.get_the_title().'</h2> <p>'.get_the_excerpt().'</p> </a>'; $out .='</div>'; endwhile; wp_reset_query(); return html_entity_decode($out); } add_shortcode('cpt_type', 'cpt_type_query');
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘wp_query not returning posts’ is closed to new replies.