admin管理员组文章数量:1291030
Based on this post, I added the code snippet below to my Wordpress site, as to display the ID in the Posts section of each post. However, it returns "critical error". Any idea what is wrong with this code?
add_filter( 'manage_posts_columns', 'column_register_wpse_101322' );
add_filter( 'manage_posts_custom_column', 'column_display_wpse_101322', 10, 3 );
function column_register_wpse_101322( $columns ) {
$columns['uid'] = 'ID';
return $columns;
}
function column_display_wpse_101322( $empty, $column_name, $post_id ) {
if ('uid' != $column_name) {return $empty;}
return "$post_id";
}
Based on this post, I added the code snippet below to my Wordpress site, as to display the ID in the Posts section of each post. However, it returns "critical error". Any idea what is wrong with this code?
add_filter( 'manage_posts_columns', 'column_register_wpse_101322' );
add_filter( 'manage_posts_custom_column', 'column_display_wpse_101322', 10, 3 );
function column_register_wpse_101322( $columns ) {
$columns['uid'] = 'ID';
return $columns;
}
function column_display_wpse_101322( $empty, $column_name, $post_id ) {
if ('uid' != $column_name) {return $empty;}
return "$post_id";
}
Share
Improve this question
edited Jun 5, 2021 at 16:42
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Jun 5, 2021 at 16:04
NickNick
1272 silver badges9 bronze badges
1 Answer
Reset to default 1Unfortunately you can't just copy code that plays a completely different role and replace users
with posts
and somehow expect this to do what you want it. The reason you get a fatal error is because you're passing in too many arguments (3) to the filter, when there are only 2 supplied.
Here's the code to achieve what you need, if I understand you correctly:
add_filter( 'manage_posts_columns', 'column_register_wpse_101322' );
add_action( 'manage_posts_custom_column', 'column_display_wpse_101322', 10, 2 );
function column_register_wpse_101322( $columns ) {
$columns[ 'uid' ] = 'ID';
return $columns;
}
function column_display_wpse_101322( $column_name, $post_id ) {
if ( 'uid' === $column_name ) {
echo $post_id;
}
}
本文标签: Code snippet to display ID gives critical error
版权声明:本文标题:Code snippet to display ID gives critical error 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741521072a2383187.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论