您可以在上筛选段塞创建wp_unique_post_slug
钩
//Register the filter
add_filter(\'wp_unique_post_slug\',\'prefix_the_slug\',10,6);
function prefix_the_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug){
//Get value from the custom field
$prefix = get_post_meta($post_ID,\'cw_event_start_date\',true);
//Only prefix certain post type and if prefix field existed
if($post_type===\'post\' && $prefix && !empty($prefix)){
//Prefix only if it is not already prefixed
preg_match (\'/^\\d\\d\\d\\d\\d\\d/\', $slug, $matches, PREG_OFFSET_CAPTURE);
if(empty($matches)){
return $prefix.\'-\'.$slug;
}
}
return $slug;
}