再次检查您是否正确使用了这些功能。尝试收集结果并输出,以便查看您正在使用的内容。
get_the_ID()
和get_queried_object_id()
有两种获取当前ID的好方法,请将它们传递给get_post_status()
.
$debug = array (
\'get_the_ID\' => get_the_ID(),
\'get_the_ID_status\' => get_post_status( get_the_ID() ),
\'get_queried_object_id\' => get_queried_object_id(),
\'get_queried_object_id_status\' => get_post_status( get_queried_object_id() ),
);
// print the results to the screen
echo \'<pre>\';
var_dump( $debug );
echo \'</pre>\';
WordPress循环中当前项的ID。
if ( get_post_status( get_the_ID() ) == \'private\' ) {
echo \' get_the_ID = private \';
} else {
echo \' get_the_ID = public \';
}
当前查询对象的ID
if ( get_post_status( get_queried_object_id() ) == \'private\' ) {
echo \' get_queried_object_id = private \';
} else {
echo \' get_queried_object_id = public \';
}