I’m about to create parser which would be inserting new custom posts.
So, it’s pretty simple
global $user_ID;
$new_post = array(
'post_title' => 'My New Post',
'post_content' => 'Lorem ipsum dolor sit amet...',
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(0)
);
$post_id = wp_insert_post($new_post);
But i have some extra logic in creating permalinks.
function my_post_type_link_filter_function( $post_link, $id = 0, $leavename = FALSE ) {
if ( strpos('%dgor%', $post_link) === 'FALSE' && strpos('%znak%', $post_link) === 'FALSE' ) {
return $post_link;
}
$post = get_post($id);
if ( !is_object($post) || $post->post_type != 'goroskop' ) {
return $post_link;
}
$day = wp_get_object_terms($post->ID, 'gday');
$month = wp_get_object_terms($post->ID, 'gmonth');
$year = wp_get_object_terms($post->ID, 'gyear');
if ( !$day || !$month || !$year ) {
return $post_link;
}
$post_link = str_replace('%gday%', $day[0]->slug, $post_link);
$post_link = str_replace('%gmonth%', $month[0]->slug, $post_link);
return str_replace('%gyear%', $year[0]->slug, $post_link);
}
add_filter('post_type_link', 'my_post_type_link_filter_function', 1, 3);
So, i need to replace some markers in my permalink structure based on custom taxonomy.
The question is: Is there any way to invoke this logic programmatically while inserting new custom post?
from http://wordpress.org/support/topic/new-post-hook