我的循环只返回一个帖子而不是全部。我第四次经历它,我没有看到任何理由为什么它这样做。谢谢你的帮助。
localStorage
已被清理,缓存也是 - 而且我在此类别中发布的帖子超过一篇:)
function rtf_custom_grid( ) {
$args = array(
'post_type' => 'apartamenty',
'post_per_page' => -1,
'nopaging' => true,
'order' => 'date',
'orderby' => 'DESC'
);
$rtf_query = new WP_Query ( $args );
while($rtf_query->have_posts() ) : $rtf_query->the_post();
$cena_1 = get_field('cena_1');
$cena_2 = get_field('cena_2');
$short_dec = get_field('short_desc');
$output = '<div class="single-apartament">';
if ( has_post_thumbnail() ) :
$output .= '<div class="rtf-apartament-thumbnail">';
$output .= '<a href="' . get_permalink() . '">' . get_the_post_thumbnail(get_the_id(), 'large') . '</a></div>';
endif;
$output .= '<div class="rtf-apartament-content">';
$output .= '<a href="' . get_permalink() .'" class="apartament-ttile">' . get_the_title() . '</a>';
$output .= '<div class="rtf-apartament-excerpt">' . $short_dec . '</div>';
$output .= '<div class="rtf-apartament-prize">';
$output .= '<span>' . $cena_1 . ' / ' . $cena_2 . '</span></div>';
$output .= '<a href="'. get_permalink() .'" class="apartament-readmore">Zobacz</a></div></div></div>';
endwhile;
wp_reset_query();
return $output;
}
add_shortcode('apartamenty', 'rtf_custom_grid');
答案 0 :(得分:1)
$output = ' <div class="single-apartament"> ';
the above line is overwriting the previous content in the variable. So its showing only the last post.
Solution :
$output.= '<div class="single-apartament">';
This will append the html code into the variable instead of overwriting it.
Hope it works for you