【发布时间】:2023-01-19 05:48:50
【问题描述】:
我正在尝试使用我创建的简码在作者页面上显示作者 ID,但它目前无法正常工作,因为简码仅输出管理员 ID。 这是我在短代码中返回的内容:
return get_the_author_meta('ID');
【问题讨论】:
-
你能发布整个简码吗?
标签: wordpress
我正在尝试使用我创建的简码在作者页面上显示作者 ID,但它目前无法正常工作,因为简码仅输出管理员 ID。 这是我在短代码中返回的内容:
return get_the_author_meta('ID');
【问题讨论】:
标签: wordpress
工作代码:
function author_id_shortcode(){
ob_start();
// We get the author ID outside loop.
global $post;
$author_id = $post->post_author;
// Now get the author ID inside loop.
$author_id = get_the_author_meta( 'ID' );
$output = get_the_author_meta( 'ID', $author_id );
ob_end_clean();
return $output;
}
add_shortcode( 'author_id', 'author_id_shortcode' );
使用 [author_id] 调用简码
【讨论】:
请在 author.php 上尝试以下代码
if (is_author()){
$author = get_queried_object();
$author_id = $author->ID;
echo $author_id;
}
【讨论】: