add_filter( 'post_type_link', function( $link, $post = 0 ) {
global $post;
if ( $post->post_type == 'projects' ) {
return home_url( '/' . $post->ID );
} else if ( $post->post_type == 'colors' ) {
return home_url( '/' . $post->ID );
} else {
return $link;
}
}, 1, 3 );
add_action( 'init', function() {
add_rewrite_rule( '([0-9]+)?$', 'index.php?post_type=projects&p=$matches[1]', 'top' );
add_rewrite_rule( '([0-9]+)?$', 'index.php?post_type=colors&p=$matches[1]', 'top' );
});
([0-9]+)?$
and you want a link and WP gave you a record with projects, and then add another rule with the same reg. expression, but want the results recording colors, a question: how do WP know that they are different record types? Answer: no, as reg. the expression is the same, WP will overwrite the previous rule last.Find more questions by tags WordPress