function slb_subscriber_column_data( $column, $post_id ) {
// setup our return text
$output = '';
switch( $column ) {
case 'title':
// get the custom name data
$fname = get_field('slb_first_name', $post_id );
$lname = get_field('slb_last_name', $post_id );
$output .= $fname .' '. $lname;
break;
case 'email':
// get the custom email data
$email = get_field('slb_email', $post_id );
$output .= $email;
break;
}
// echo the output
echo $output;
}
function slb_register_custom_admin_titles() {
add_filter(
'the_title',
'slb_custom_admin_titles',
99,
2
);
}
function slb_custom_admin_titles( $title, $post_id ) {
global $post;
$output = $title;
if( isset($post->post_type) ):
switch( $post->post_type ) {
case 'slb_subscriber':
$fname = get_field('slb_first_name', $post_id );
$lname = get_field('slb_last_name', $post_id );
$output = $fname .' '. $lname;
break;
}
endif;
return $output;
}以上是插件的代码。我正在上一门关于udemy.com的课程。提交人没有回应。
问题:虽然整个方法是在没有任何第三方的情况下创建一个设置,但作者似乎以某种方式使代码依赖于ACF插件。一旦我禁用ACF插件,屏幕就会变成空白:

我觉得罪魁祸首是这个部分:get_field,我怎样才能摆脱这个。在一般情况下,从WordPress函数中可以使用什么来提取这些信息而不需要这些信息呢?

发布于 2021-04-18 15:28:04
您可以使用默认的WP函数get_post_meta从文章中获取元数据,下面是官方文档https://developer.wordpress.org/reference/functions/get_帖子_元/的链接
例如,必须将get_field('slb_first_name', $post_id )替换为get_post_meta($post_id, 'slb_first_name', true)
https://wordpress.stackexchange.com/questions/386828
复制相似问题