Tag Info

New answers tagged

1

wp_insert_post runs when a post is updated as well. If you scan the source you will see numerous blocks of code switching between an update or not an update. In fact, wp_update_post() just passes data, after a little processing, to wp_insert_post() for the bulk of the work. That is why your code runs more than you think it should-- the hook doesn't work as ...


1

The second parameter to wp_set_object_terms() takes an array, integer, or string. (array/int/string) (required) The slug or id of the term (such as category or tag IDs), will replace all existing related terms in this taxonomy. To clear or remove all terms from an object, pass an empty string or NULL. Integers are interpreted as tag IDs. ...


2

Implode turns your array like this array( 'Audi', 'BMW', 'Mercedes-Benz' ) into a string separated by the delimiter set in the first parameter of the function, in this case , a comma and a space. In a way you can turn an array into a CSV from this. The result is this: Audi, BMW, Mercedes-Benz. The way WordPress works, it looks for an existing term (within ...


0

WordPress will take care about unique slug. If you want to redirect to the post after it has been created, you can get the permalink using the post ID which is returned by wp_insert_poost() if it was successfull: $my_post = array( 'post_title' => 'My post', 'post_content' => 'This is my post.', 'post_status' => 'publish', ...


0

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 { ...


0

From the codex page You must pass 2 for the $accepted_args variable in add_filter() if you want to access $postarr. So use this: add_filter( 'wp_insert_post_data', 'set_post_title', 99, 2 );



Top 50 recent answers are included