【发布时间】:2021-09-26 08:42:45
【问题描述】:
我有一个带有标准 while 循环的 single-page.php。在该循环中,我有另一个循环,我想输出我正在查看/查看的帖子标题,但是因为我在函数 futureEvent 的内部循环中有 get_the_title(),所以它输出的是该帖子的标题:
while (have_posts()) {
the_post(); ?>
...
$futureEvents = get_posts($args);
foreach ($futureEvents as $post) {
$futureEvents = new WP_Query($args);
if ($futureEvents->have_posts()) {
echo '<div class="related-content"><h3>Upcoming ' . get_the_title() . ' Events</h3></div>';
?>
<article class="post-item">
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</article>
}
}
}
在 wordpress 中,我有一个添加了三个帖子的 CPT。
我使用了 get_the_title(118),但是它硬编码了帖子的 id,但我想从我的 CPT 获取任何帖子的标题。
我尝试使用 get_the_title($post->$ID) 和 get_the_title($post_id),但仍然输出不正确的帖子标题。
谁能看到我如何从该循环中获取我正在/正在查看的帖子的标题?
【问题讨论】:
标签: php wordpress if-statement custom-post-type posts