我将要创建一个解析器,它将插入新的自定义帖子。所以,这很简单
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);
但我在创建永久链接时有一些额外的逻辑。
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);
因此,我需要根据自定义分类法替换permalink结构中的一些标记。
问题是:Is there any way to invoke this logic programmatically while inserting new custom post?