我有一個自定義wordpress函數,顯示特色食譜的數量。當查詢中有showposts=-1
時,該功能正常工作。然而,當我把'showposts = 5'只顯示我的兩個帖子。自定義wordpress函數沒有顯示正確的帖子數
下面是我的功能
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');
這個問題似乎是與
if (get_field('featured-pika-recipe') == 'Yes') {
除去這一點,職位數目出現罰款。任何方式我可以解決這個問題?
在這個頁面上https://codex.wordpress.org/Class_Reference/WP_Query我看到posts_per_age已經取代showposts參數開始WP 2.1,所以只是好奇,是什麼版本的WP的你在 – Satya
@Satya im 4.2版 – user38208
@Satya,'showposts' [still works](https://core.trac.wordpress.org/browser/tags/4.2.2/src/wp-includes/query.php#L2463 ) – rnevius