从Frontend WordPress插入帖子时,也保存自定义元框
$student = array(
'post_title' => wp_strip_all_tags( $student_name ),
'post_status' => 'private',
'post_type' => 'student'
);
wp_insert_post($student);
这就是我从前端插入帖子的方式。正常工作。 但是我还需要从Frontend和帖子中保存一些自定义字段,并且需要在后端显示值(仅在输入字段中以文本格式为单位)。因此,是否存在类似的东西“ my_custom_filed” => 'custom_value':
$student = array(
'post_title' => wp_strip_all_tags( $student_name ),
'my_custom_filed' => 'custom_value'
'post_status' => 'private',
'post_type' => 'student'
);
wp_insert_post($student);
因此,我可以在后端打印自定义字段的值
function studentDataMetaBoxStructure(){
global $post;
$my_custom_filed = get_post_meta($post->ID,'my_custom_filed',true);
echo $my_custom_filed;
}
,但我在$ my_custom_filed中什么也没得到;
$student = array(
'post_title' => wp_strip_all_tags( $student_name ),
'post_status' => 'private',
'post_type' => 'student'
);
wp_insert_post($student);
This is how I'm inserting post from the frontend. it is working fine.
But I need to save some custom fields also from frontend along with post and need show the values in backend(just in text format not in input field). So is there anything exists like this 'my_custom_filed' => 'custom_value':
$student = array(
'post_title' => wp_strip_all_tags( $student_name ),
'my_custom_filed' => 'custom_value'
'post_status' => 'private',
'post_type' => 'student'
);
wp_insert_post($student);
So I can print the value of custom fields in backend
function studentDataMetaBoxStructure(){
global $post;
$my_custom_filed = get_post_meta($post->ID,'my_custom_filed',true);
echo $my_custom_filed;
}
But I'm getting nothing in $my_custom_filed;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是您在插入后保存元箱的方式。
This is how you save meta box while post insertion.