New answers tagged


wp_insert_post was introduced in changeset 2887, and was to fix bug #1681. I couldn't find the save_post hook's original provenance, but it was most recently added to core in changeset 3291, related to ticket #2063. Evidently it had existed in 1.5.2 (although version control does not support this theory) and needed to be added back for back-compat. So ...


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.


Ok, so after some fiddling, I've got things working. It turns out that I was setting the add_action hooks incorrectly for the AJAX part. The hooks need to be: add_action( 'wp_ajax_nopriv_MYFUNCTION', 'MYFUNCTION' ); and add_action( 'wp_ajax_MYFUNCTION', 'MYFUNCTION' ); my case and original code the function ('MYFUNCTION') in question was to ...


Instead of wp_insert_posts, create your own "call" using $wpdb which you can then set your own database e.g. $table_name = $wpdb->prefix . 'tablename'; $wpdb->insert( $table_name, array( // data to add ) ); You can read more on custom tables at


Ultimately the solution that I found was to use global $post; to retrieve the current post's ID. Immediately after wp_insert_post( $new_cpta ); above, I added global $post; $currentid = $post->ID; Then I was able to update the post meta for the correct post with $currentid in place of $post_id.


Try this code after the $bio = wp_insert_post( $my_bio_post ); line: $terms = isset($_POST['my_pet']) ? array_filter($_POST['my_pet']) : 0; if ($terms && $bio) wp_set_object_terms($bio, $terms, 'Cats'); See wp_set_object_terms() for more info and make sure the Cats taxonomy and the terms in your checkboxes is already available.

Top 50 recent answers are included