I’ve created a put up to posts relationship utilizing ACF. On the one web page of considered one of my CPTs I wish to add a prettified ID to the top of the slug to load totally different values on the web page (/my-archive/my-single-post/ID
) and have that ID saved to a question variable known as custom_id. I additionally are not looking for the web page to redirect to the unique slug (/my-archive/my-single-post/
).
I’ve managed to do the next:
add_action( 'init', 'add_custom_id_rewrite_rules' );
perform add_custom_id_rewrite_rules() {
add_rewrite_rule( '^my-archive/([^/]*)/([0-9]+)?$', 'index.php?post_type=my_post_type&pagename=$matches[1]&custom_id=$matches[2]', 'high' );
}
add_filter( 'query_vars', 'add_custom_id_query_vars' );
perform add_custom_id_query_vars( $query_vars ) {
$query_vars[] = 'custom_id';
return $query_vars;
}
From all over the place I learn, this could work. I’ve put in the Rewrite Rule Analyzer and it detects my custom_id appropriately. Nonetheless, regardless of it being thought of appropriate I nonetheless get redirected to /my-archive/my-single-post/
.
I would like the question to nonetheless pull the_title()
from that single put up I simply need to have the ability to question custom_id to vary issues on the web page.
Ideas?