0

I'm trying to insert a custom post through a form. It's a brief post, most content are custom meta fields updated with add_post_meta. So far, post inserting is working fine, except for a detail. This is the post insert query I'm doing:

$venta = wp_insert_post(array(
  'post_name'      => "venta-$stamp",
  'post_title'     => "Venta $stamp",
  'post_type'      => 'venta',
  'comment_status' => 'closed',
  'ping_status'    => 'closed',
  // 'post_status'    => 'published'
));

Left as shown, it inserts posts as Draft without hassle. But if I uncomment post_status, the post gets inserted, but it doesn't show up in the All Posts Post Table related to that post type.

If I run a WP_Query for that post_type, it shows me the published posts and the post count —both in the Query and in the Post Table top tabs— reflects that those posts actually exist in the database, but can't see them in the Post Table. The only way to see a post in the WP Admin is editing the URL manually to get to the post, so I can modify or delete them.

What is actually happening? What can I do to test what is going on? Any docs I should look at, besides the Developer Resources for wp_insert_post?

1 Answer 1

2

Well, the problem is quite simple: it's publish, not published.

According to the documentation:

post_status (string / array) - use post status. Retrieves posts by Post Status. Default value is 'publish', but if the user is logged in, 'private' is added.

2
  • did you solve it? for me, it is already "publish" but I can't see the post in the page. it is already in database.
    – doniyor
    Commented Dec 22, 2018 at 7:33
  • It happened to me while working on this project that after saving so many posts as published instead of publish, they didn't show up in any proper query except the database. You could try to change the post_status of the affected posts as publish so they can show up. Commented Jan 19, 2019 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.