I have a requirement that needs to me to create posts with some custom fields from outside of Wordpress
I have been able to add the post, necessary custom fields from outside using standard WP functions.
I can also see the entries in postmeta and posts table.
But, these values are not available to me in the frontend where I want to display them. However when I open this post in the dashboard's write panel, I see that all the values are filled correctly and if I just update it, the values start appearing in the front end.
I'm sure I'm missing out something here. So, any help is much appreciated.
Below is the code I'm using currently to achieve the above
$post = array(
'post_name' => 'g-test-3', // The name (slug) for your post
'post_title' => 'G Testing 3', // The title of your post.
'post_status' => 'publish', // Default 'draft'.
'post_type' => 'post',// Default 'post'.
'post_author' => 5090,// The user ID number of the author. Default is the current user ID.
'post_excerpt' => '', // For all your post excerpt needs.
'post_date' => date('Y-m-d H:i:s'), // The time post was made.
'comment_status' => 'open', // Default is the option 'default_comment_status', or 'closed'.
'post_category' => array(644)// Default empty.
);
$posted = wp_insert_post( $post, true );
echo 'post id: '. $posted;
$added = array();
$added[]= update_post_meta($posted, 'external_url', 'http://example.com/external-url', false);
$added[]= update_post_meta($posted, 'media', 'Yes', false);
$added[]= update_post_meta($posted, 'remarks', 'These are the example remarks', false);
$added[]= update_post_meta($posted, 'alternate_headline', 'Alternate headline for G Testing', false);
$added[]= update_post_meta($posted, '_mf_write_panel_id', '13', false);