Created
April 9, 2018 20:27
-
-
Save whoisryosuke/bf2afae0a1819a7623421ce7de1f4dbe to your computer and use it in GitHub Desktop.
WORDPRESS: Create new post with meta data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Credits: https://wordpress.stackexchange.com/questions/106973/wp-insert-post-or-similar-for-custom-post-type | |
$post_id = wp_insert_post(array ( | |
'post_type' => 'your_post_type', | |
'post_title' => $your_title, | |
'post_content' => $your_content, | |
'post_status' => 'publish', | |
'comment_status' => 'closed', // if you prefer | |
'ping_status' => 'closed', // if you prefer | |
)); | |
if ($post_id) { | |
// insert post meta | |
add_post_meta($post_id, '_your_custom_1', $custom1); | |
add_post_meta($post_id, '_your_custom_2', $custom2); | |
add_post_meta($post_id, '_your_custom_3', $custom3); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment