generate unique slug while inserting post

You don’t have to think about it – WordPress will take care of this. Let’s take a look at wp_insert_post source code… On line 3203 you’ll find: if ( empty($post_name) ) { if ( !in_array( $post_status, array( ‘draft’, ‘pending’, ‘auto-draft’ ) ) ) { $post_name = sanitize_title($post_title); } else { $post_name=””; } } else { … Read more

Can I trigger the publish_post hook by using wp_insert_post?

It’s triggered in wp_publish_post() that calls: wp_transition_post_status( ‘publish’, $old_status, $post ); that fires up action calls, dynamically with: do_action( “{$new_status}_{$post->post_type}”, $post->ID, $post ); where “{$new_status}_{$post->post_type}” becomes “publish_post” in your case.

Add a default meta_value to new posts

Add this to your functions.php in your template folder. <?php //Set Default Meta Value function set_default_meta_new_post($post_ID){ $current_field_value = get_post_meta($post_ID,’YOURMETAKEY’,true); //change YOUMETAKEY to a default $default_meta=”100″; //set default value if ($current_field_value == ” && !wp_is_post_revision($post_ID)){ add_post_meta($post_ID,’YOURMETAKEY’,$default_meta,true); } return $post_ID; } add_action(‘wp_insert_post’,’set_default_meta_new_post’); ?>

post_date_gmt and post_date [duplicate]

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

wp_insert_post featured image from library

You can use the function set_post_thubmnail(). After you inserted your post, just call this one, and you are ready to go. $yourpostid = wp_insert_post( $args ); // Define the post in the args first set_post_thumbnail( $yourpostid, $thumbnail_id ); // set the ID of your thumbnail to be the featured image of your newly created post.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)