• hi all,

    i am hoping i am just missing something easy.

    i have a script that inserts posts. i get no errors when the script runs, and all the posts end up in the wp_posts table (and the meta is in wp_postmeta), but if i try to edit any of those posts in admin, i get this error:
    “You attempted to edit an item that doesn’t exist. Perhaps it was deleted?”

    i get a 404 if i try to view the post.

    here is a code snippet:

    $post = array(
    ‘post_author’ => 1,
    ‘post_title’ => $title,
    ‘post_name’ => $slug,
    ‘post_content’ => $content,
    ‘post_type’ => ‘post’,
    ‘post_status’ => ‘publish’,
    ‘post_category’ => array(1487),
    ‘tags_input’ => $tags,
    );
    $keywords = $tags;
    $metatitle = $title;
    $metadescription = strip_tags($content);

    $newid = wp_insert_post($post);
    if ($newid > 0)
    {
    add_post_meta($newid, ‘title’, $metatitle);
    add_post_meta($newid, ‘description’, $metadescription);
    add_post_meta($newid, ‘keywords’, $keywords);
    }

    any help, or pointers on where i can look next, would be greatly appreciated. thanks much in advance!

Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello laz0rama,

    Have you installed any new plugin ? May be after that plugin install this error occur.If Yes please try deactivating plugins one by one and check the things working or not.And if you are using the Total Cache plugin the Flushed the page cache and try.

    Thanks

    @laz0rama,
    After executing your code, can you see the posts in the dashboard?

    Also, what is your permalinks structure set to?

    Thread Starter laz0rama

    (@laz0rama)

    @shariqkhan2012: thanks for the response. no, the posts do not appear in the dashboard. when i try to edit them directly i get the error above. the permalink structure is:

    /%category%/%postname%

    Thread Starter laz0rama

    (@laz0rama)

    @clarion: thanks for the thoughts. no new plugins have been installed, although i probably should try disabling the existing few basic ones. no caching plugin.

    @laz0rama, I am a bit confused. If you don’t see the posts in the dashboard, how are you trying to edit those?

    Thread Starter laz0rama

    (@laz0rama)

    by entering the edit url directly in the address bar:

    https://domain.com/wp-admin/post.php?post=1016&action=edit

    where i put the wp_posts.ID as the post number.

    also, i have tried manually inserting an identical post, and it works fine, viewable and editable. i am trying to look in the database to see what gets created when i enter manually vs via my script, and i haven’t found anything yet. but one thing i did notice, is that i see the tags created in the wp_terms and mapped to the post in wp_term_relationships, but i cannot find where the categories are stored. i don’t see them in wp_terms. any ideas on that?

    Thread Starter laz0rama

    (@laz0rama)

    hmmmm… now i’m really confused.

    i just manually created a new category, i can see it in the list of categories on the admin page. but nothing appeared in the wp_terms table.

    i am missing something…

    Thread Starter laz0rama

    (@laz0rama)

    nevermind the last comment, i am braindead. i was logged into a different db!

    Thread Starter laz0rama

    (@laz0rama)

    brain-dead, that’s me.

    i figured it out. turns out it was merely a current working directory problem. the script gets called from one domain, but resides in, and is supposed to impact, another domain entirely. so when the script got called, the cwd was in the original domain, and therefore when i loaded the wordpress bootstrap files, it was actually loading the ones for the wrong domain/website. i was using relative paths for those, if i’d used absolute paths it would have worked to begin with. instead i now do a chdir() as the first line of my script. and now posts are there!

    sorry for being lame!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘wp_insert_post appears to work, but no post on site’ is closed to new replies.