Posts added with wp_insert_post are moved to trash automatically

@iamjonesy, One possibility is you your theme already has some deleted posts with similar title or slugs or theme provider has modified the hook with some filter.

Here is a few things you can do to check:
Try to find the page with title
If it’s in the trash, update it & change it’s status;
Otherwise, programmatically create it.

foreach($data['title'] as $title)
{

// Initialize the page ID. This indicates no action has been taken.
    $page_id = -1;

// First, try to get the page
$page = get_page_by_title( $title, OBJECT, 'page' );

// If the page doesn't exist, create it
if( null == $page ) {

Otherwise, if the page is in the trash, update it and change its status to publish

} elseif( 'trash' == strtolower( $page->post_status ) ) {

    $page->post_status="publish";
    -----your code ---------

Hope this help 🙂

Leave a Comment