Continuing the discussion from Unique number or ID:
// Change permalink structure to end with post ID
function custom_hp_listing_permalink_structure() {
global $wp_rewrite;
$wp_rewrite->extra_permastructs['hp_listing']['struct'] = '/hp_listing/%hp_listing%/%post_id%';
}
add_action( 'init', 'custom_hp_listing_permalink_structure' );
// Replace post ID placeholder in generated permalink URL
function custom_hp_listing_post_link( $permalink, $post ) {
if ( $post && 'hp_listing' === $post->post_type ) {
$permalink = str_replace( '%post_id%', $post->ID, $permalink );
}
return $permalink;
}
add_filter( 'post_type_link', 'custom_hp_listing_post_link', 10, 2 );
I’ve successfully implemented this, but I’m aiming to change the URL structure to “p/post_id.” Despite multiple attempts, the listing URL becomes dysfunctional, preventing access to any listings. Can you assist me with this issue?