Articles of wp insert post

wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated

So, I have a plugin that uses Ajax to dynamically build the post content piece by piece for a custom post type. Once the user has build their page, they hit Update/Publish and Ajax sends the entire built page to a the main plugin PHP file where I am attempting to call wp_insert_post(). Here is […]

how can I set the post author of a post I just created with php?

I’m using php to dynamically create a custom post, and I need the author to be someone other than the logged in user. I found this https://stackoverflow.com/questions/5759359/wordpress-manually-set-the-author-of-a-post-in-php but I’m wondering if there is a way to do it after the post is already inserted. I guess I could just do a db query…

HTML Entities in Post Title

I’m inserting posts into wordpress using a script which is loaded through CRON. Before inserting each post I am checking whether the post with the same title exists or not. Below is the snippet I’m using: if( is_null(get_page_by_title( $page_title, ‘OBJECT’, $post_type )) ) { // Create post object $my_post = array( ‘post_title’ => “Food & […]

wp_insert_post -> post_content not showing

I have a problem with wp_insert_post. When I’m attempting to insert my post, the post_content essentially shows up as just blanks spaces. I even went into MySQL to confirm. Everything else, post_title, post_excerpt, etc shows up just fine. I did a print_r($this->postData) Just prior to passing this to wp_insert_post just to be sure it wasn’t […]

How to use wp_insert_post to update meta box?

I’m trying to use wp_insert_post to create a front-end submission form so visitors can create a post AND update the meta box fields of that post — not the custom fields. For example, when I use the following in the submission form… <?php update_post_meta($post_id, $meta_key, $meta_value); ?> …it updates the built-in custom field section of […]

Insert WordPress page via external (cron) script?

I’m trying to write a php script that I can run out of cron to create new WordPress pages. Unfortunately, I can’t find any documentation on how to do this. I’m using the WP scripts rather than directly manipulating the SQL…but still no joy. The below runs with no errors…but also produces no pages. I […]

can't edit post_modified in wp_insert_post (bug?)

It smelss like a bug but adding the post_modified in wp_insert_post isn’t working: $wp_test = array( ‘post_title’ => ‘test’, ‘post_content’ => ‘test’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘test’, ‘post_author’ => 1, ‘post_date’ => ‘2015-01-22 22:00:12’, ‘post_date_gmt’ => ‘2015-01-22 22:00:12’, ‘post_modified’ => ‘2016-04-18 12:12:12’, ‘post_modified_gmt’ => ‘2016-04-18 12:12:12’, ‘comment_status’ => ‘closed’ ); $wp_id = wp_insert_post( $wp_test […]

wp_insert_post add meta_input

In the documentation of wp_insert_post there is a changelog on half of the page which says the following: Since: WordPress 4.4.0 A ‘meta_input‘ array can now be passed to $postarr to add post meta data. I’m using WordPress 4.4.2. I’ll try to add a new post by running the code as follows: function handle_post($post) { […]

tax_input not working wp_insert_post

I am using wp_insert_post and all the fields are working except tax_input is working. Is there something wrong with my code? $customtax = array( ‘product_link’ => $link, ‘product_price’ => $price, ‘product_description’ => $desc ); $my_post = array( ‘post_title’ => $title, ‘post_content’ => $content, ‘post_type’ => ‘products’, ‘tax_input’ => $customtax ); Thank you in advance

What hook should be used to programmatically create a post only when master post is updated?

Pippin and Jean-Baptiste Jung have very good tutorials on how to programmatically create content when a new post is published using these four actions hooks… publish{post_type} add_action(‘new_to_publish_{post_type}, add_action(‘draft_to_publish_{post_type}, add_action(‘pending_to_publish_{post_type} … to run this script… global $user_ID; $new_post = array( ‘post_title’ => ‘My New Post’, ‘post_content’ => ‘Lorem ipsum dolor sit amet…’, ‘post_status’ => ‘publish’, ‘post_date’ […]