Last active
February 14, 2023 17:46
-
-
Save someguy9/7b157bf9bce72604663c18d05037041f to your computer and use it in GitHub Desktop.
Insert a post programmatically in WordPress https://smartwp.com/wordpress-insert-post-programmatically/
This file contains hidden or 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 | |
// Insert post programmatically | |
$new_post = array( | |
'post_title' => 'My new post', | |
'post_content' => 'Content to insert.', | |
'post_status' => 'publish' | |
); | |
$post_id = wp_insert_post( $new_post ); | |
if( $post_id ){ | |
echo "Post inserted successfully with the post ID of ".$post_id; | |
} else { | |
echo "Error, post not inserted"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment