wp_insert_post() Callback?
$post_id = wp_insert_post( $arg ); #returns post ID $permalink = get_permalink( $post_id ); #returns the permalink Codex: http://codex.wordpress.org/Function_Reference/wp_insert_post
$post_id = wp_insert_post( $arg ); #returns post ID $permalink = get_permalink( $post_id ); #returns the permalink Codex: http://codex.wordpress.org/Function_Reference/wp_insert_post
From the comments in the WP_Post class in wp-includes/post.php: You can set the post date manually, by setting the values for ‘post_date’ and ‘post_date_gmt’ keys. So if you’re adding a post programmatically, and you want a date attached, you should set both keys. (If you leave them blank, WordPress will use the appropriate current date … Read more
As Rarst mentioned I had to use wp_update_post(), but then there is a little trick – one must also set edit_date = true otherwise it has funny behavior. The final code looks like this: function schedule() { $postdate = date(‘2014-06-11 01:00:00’); $postdate_gmt = date(‘2014-06-11 05:00:00’); $post = array( ‘ID’ => 11, ‘post_status’ => ‘future’, ‘post_type’ … Read more
wp_insert_post not returning post ID? [closed]
Before copying files (rename()) to the final destination I set time parameter for wp_upload_dir() (instead of trying to make wp_handle_upload() to pass it) and it transfers files to appropriate directories now. $uploads = wp_upload_dir( $upload_date ); $output_dir = $uploads[ ‘path’ ]; rename( $filename, $new_filepath );
I find out the problem and the solution. I debugged the “wp_set_object_terms” by using “is_wp_error” and I got “Invalid Taxonomy” message, then I realized that when the posts was being created that term didn’t exists. So I change the hook to “init” in the programmatically_create_post() function, and voila! Below this line the code working: <?php … Read more
Use this code snippet to use another function, function my_function( $post_id ) { //Some code } add_action( ‘save_post’, ‘my_function’ ); This fires when a post is inserted.
Gr8 job… only thing missing is the action and the timing for it to work… try this: $ins_home = array( ‘post_title’ => ‘Home’, ‘post_name’ => ‘my-home-site’, ‘post_status’ => array(‘publish’), ‘post_type’ => ‘page’, ‘comment_status’ => ‘closed’, ‘ping_status’ => ‘closed’ ); $ins_home_id = wp_insert_post($ins_home, 10, 1); $result = $wpdb->query(“SELECT wpost.post_name FROM $wpdb->posts wpost WHERE wpost.post_name=”my-home-site””); if($result < … Read more
See those two hooks in the hacked Core code you posted? do_action(‘save_post’, $post_ID, $post); do_action(‘wp_insert_post’, $post_ID, $post); Those are what you need to use to do this right. function run_on_update_post($post_ID, $post) { var_dump($post_ID, $post); // debug include ‘../push/send_message.php’; sendNotification($post[‘post_title’],$post[‘guid’]); return $post_ID; } add_action(‘save_post’, ‘run_on_update_post’, 1, 2); save_post runs every time the post is saved. I … Read more
Since you add a reference to my previous answer, let me share how I tested it: Setup on site A – XML-RPC Client include_once( ABSPATH . WPINC . ‘/class-IXR.php’ ); include_once( ABSPATH . WPINC . ‘/class-wp-http-ixr-client.php’ ); $client = new WP_HTTP_IXR_CLIENT( ‘http://example.tld/xmlrpc.php’ ); // <– Change! $client->debug = true; $result = $client->query( ‘wp.newPost’, [ 0, … Read more