WordPress循环显示其他帖子标题,而不仅仅是一个


WordPress loop displaying other post titles instead of just one

我有一个问题,帖子显示的标题来自其他帖子,而不是它唯一的一个帖子。其他部分也可以,即没有其他重复,只有标题。

我生成内容的代码:

get_header();
$the_query = new WP_Query( 'category_name=careers&showposts=5' );
while ( $the_query->have_posts() ) :
    $output = "";
    $the_query->the_post();
    $output_title .= get_the_title();
    $output_content .= get_the_content();
    $output_type = get_field('job_type');
    $output_salary = get_field('job_salary');
    $output_intro = get_field('job_intro');
    $careers.= '
        <div class="careers">
            <h3>'.$output_title.'</h3>
            <p class="type">'.$output_type.'</p>
            <p class="salary">'.$output_salary.'</p>
            <p>'.$output_intro.'</p>
    </div>
    ';
endwhile;
wp_reset_postdata();

因此,最新的帖子显示了一个标题,这很好,但第二个帖子显示了标题+最新,第三个职位显示了标题+2+1。例如:

  • 岗位1
  • 岗位1岗位2
  • 职位1职位2职位3

应该在什么时候:

  • 岗位1
  • 岗位2
  • 岗位3

看起来像是在连接字符串,即删除=前面的点

$output_title .= get_the_title();

应该是

$output_title = get_the_title();

问题是由您使用$output_title .= get_the_title()引起的。应将.=更改为仅=

while ( $the_query->have_posts() ) :
    $output = "";
    $the_query->the_post();
    $output_title = get_the_title(); // Change this line
endwhile;