Skip to content

Instantly share code, notes, and snippets.

@someguy9
Last active February 14, 2023 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save someguy9/7b157bf9bce72604663c18d05037041f to your computer and use it in GitHub Desktop.
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/
<?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