我想获取循环外部的当前帖子/页面id(在header.php中),并将此id用于高级自定义字段插件以获取字段。
但我无法从首页、存档页(标签、作者、类别等)获得正确的id。
这是代码
if ( is_singular( \'post\' ) ) {
$post_id = $wp_query->post->ID;
echo \'post id\' . $post_id;
} elseif ( is_shop() ) {
$post_id = get_option( \'woocommerce_shop_page_id\' );
echo \'post id\' . $post_id;
} else {
$post_id = get_queried_object_id();
echo \'post id\' . $post_id
}
还有一个问题,有没有更好的方法来获取所有外部循环页面的id?我只是担心我的代码仍然缺少一些页面类型。