首页 > 解决方案 > 上一篇文章 ID 未使用此代码显示

问题描述

尝试使用此代码获取上一个帖子 ID,但它只显示当前帖子 ID

$prev_post = get_adjacent_post(false, '', true);
if(!empty($prev_post)) {

$xx = get_the_ID($prev_post->ID);
$yy = get_the_ID($post->ID);
echo $xx;
echo $yy;

标签: phpwordpresswordpress-theming

解决方案


请尝试一下:

$prev_post = get_adjacent_post(false, '', true); 
echo $prev_post->ID;

推荐阅读