Internet does not have a solution for this specific condition. First I create a new post as below:
$user_suan = wp_get_current_user();
$args = array(
'author' => $user_suan->ID,
'post_type' => 'CutePostType',
);
$current_user_posts = get_posts( $args );
if(count($current_user_posts) == 0) {
$my_post = array(
'post_title' => 'COOLPOSTNAME',
'post_status' => 'publish',
'post_type' =>'CutePostType',
'post_author' =>$user_suan->ID
);
wp_insert_post( $my_post );
$current_user_posts = get_posts( $args );
$current_user_post = $current_user_posts[0];
update_post_meta( $current_user_post->ID, 'MYLOVELYMETAFIELD', '');
After that my lovely meta field appear on the edit screen of post. I can populate it by hand. Save or use its all ok. Untill now there is no problem.
But when I use the code below it just removes my lovely meta field from the post edit screen. But at the frontend(post template), I am able to ask for the metafields of the post and display them correctly with proper unserializations. Problem is, I want to see my lovely meta field on the "post edit" page as a lovely string or etc. (wp-admin/post.php action=edit)
$MYLOVELYMETAFIELDVALUE= array('hedge'=>array('sonic'=>'dog','sound'=>'woofwoof'));
update_post_meta( $current_user_post->ID, 'MYLOVELYMETAFIELD', $MYLOVELYMETAFIELDVALUE);
How can I make them editable from post edit page.
Internet does not have a solution for this specific condition. First I create a new post as below:
$user_suan = wp_get_current_user();
$args = array(
'author' => $user_suan->ID,
'post_type' => 'CutePostType',
);
$current_user_posts = get_posts( $args );
if(count($current_user_posts) == 0) {
$my_post = array(
'post_title' => 'COOLPOSTNAME',
'post_status' => 'publish',
'post_type' =>'CutePostType',
'post_author' =>$user_suan->ID
);
wp_insert_post( $my_post );
$current_user_posts = get_posts( $args );
$current_user_post = $current_user_posts[0];
update_post_meta( $current_user_post->ID, 'MYLOVELYMETAFIELD', '');
After that my lovely meta field appear on the edit screen of post. I can populate it by hand. Save or use its all ok. Untill now there is no problem.
But when I use the code below it just removes my lovely meta field from the post edit screen. But at the frontend(post template), I am able to ask for the metafields of the post and display them correctly with proper unserializations. Problem is, I want to see my lovely meta field on the "post edit" page as a lovely string or etc. (wp-admin/post.php action=edit)
$MYLOVELYMETAFIELDVALUE= array('hedge'=>array('sonic'=>'dog','sound'=>'woofwoof'));
update_post_meta( $current_user_post->ID, 'MYLOVELYMETAFIELD', $MYLOVELYMETAFIELDVALUE);
How can I make them editable from post edit page.
Share Improve this question edited Jun 19, 2020 at 3:11 KBA asked Jun 17, 2020 at 20:58 KBAKBA 12 bronze badges1 Answer
Reset to default 0Solution is : https://developer.wordpress/plugins/metadata/managing-post-metadata/#hidden-arrays
Arrays are hidden in default. Please code your own post edit screen.
Thank you myself! This helps another one.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742290443a4416084.html
评论列表(0条)