php - Custom wordpress function not showing the right number of posts -


i have custom wordpress function shows number of featured recipes. function works fine when showposts=-1 in query. when put 'showposts=5' 2 of posts shown.

below function

 function pika_featured_recipes_shortcode() {     ob_start();      echo '<div class="featured-box-heading"> featured recipes </div>';     echo '<div class="featured-box">';      $temp = $wp_query;     $wp_query = null;     $wp_query = new wp_query();     $wp_query->query('showposts=5&post_type=cp_recipe&order=desc&orderby=date' . '&paged=' . $paged);       while ($wp_query->have_posts()):     $wp_query->the_post();     $entry_id = get_the_id();     $entry_link = get_permalink($entry_id);     $entry_image = get_post_thumbnail_id($entry_id);     $entry_title = get_the_title($entry_id);     $entry_description = get_post_meta($entry_id, '_cp_recipe_short_description', true);     $entry_excerpt = get_post_meta($entry_id, '_cp_recipe_excerpt', true);      $likes = get_post_meta( $entry_id, '_cp_likes', true );      if (get_field('featured-pika-recipe') == 'yes') {           echo '<div class="featured-result-box item ">         <div class="box">         <div class="pika-featured-box-img">';         if(!empty($entry_image)) {             echo '<a href="'.$entry_link.'">'.wp_get_attachment_image($entry_image, 'cp_298_192').'</a>';         }          echo' </div><!-- /.box-img -->';          echo'<div class="box-entry">         <h5 class="pika-featured-title"><a href="';          echo $entry_link;         echo '">';         echo $entry_title;          echo'</a></h5>';         echo $trimmed = wp_trim_words( $entry_description, $num_words = 15, $more = null );          echo'</div><!-- /.box-entry -->';         echo'</div>';         echo'</div>';          echo'<div style="clear:both"></div>';     }      endwhile;      wp_reset_query();     echo '</div>';     $output = ob_get_clean(); return $output;}    add_shortcode( 'pika_featured-recipes', 'pika_featured_recipes_shortcode' ); 

the problem seems

if (get_field('featured-pika-recipe') == 'yes') {  

removing , number of posts appear fine. way can resolve this?

maybe because 2 posts ( of last 5 posts call ) got

get_field('featured-pika-recipe') == 'yes'

you can try add custom field directly query last 5 posts custom field following code

'meta_key'      => 'featured-pika-recipe', 'meta_value'    => 'yes' 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -