I’ve got a script that loops through some data and automatically creates some posts.
foreach($data['title'] as $title)
{
$my_post = array(
'post_title' => $title,
'post_content' => $data['descr']["{$title}"],
'post_status' => 'publish',
'post_author' => 1,
'post_category' => array(7)
);
// Insert the post into the database
$post_id = wp_insert_post( $my_post );
add_post_meta($post_id, 'web_link', $data['link']["{$title}"]);
}
After the script is run I got to posts in the backend and see them listed as published. I then go to the homepage (my posts list page) but there are none listed. I go back to the backend to see they have all been moved to trash. I try to restore them all but the same thing just keeps happening.
Any ideas?
@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.
Otherwise, if the page is in the trash, update it and change its status to publish
Hope this help 🙂