我有一个自定义的帖子类型模板,我在其中循环浏览所有帖子。我正在尝试的是,当我转到自定义帖子页面时,我想在循环中获取当前帖子id。
因此,我尝试检查循环中的帖子的永久链接是否相同。如果相同,我将获取循环中当前帖子的帖子id。
这是我试过的代码
首先尝试让permalink在外部检查它在循环内部
$permalink = get_permalink();
现在我得到了当前的post permalink现在我想得到当前的post idif($query->have_posts()) :
while ($query->have_posts()) : $query->the_post();
if(the_permalink()==$permalink){
echo get_the_ID();
}else{
echo "not found";
}
endwhile;
wp_reset_postdata();
endif;
我试过这个single-{custom-post-name}.php
我正在not found
.谁能给我一个方法来获取此模板中当前的帖子id?