Using Post ID in Listing URL

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?

Sorry, I can’t suggest anything regarding this since it’s not a HivePress-specific issue. HivePress registers the listing post type using the core register_post_type function so any working solutions for changing permalinks for hp_listing post type should be ok. You can also consider asking or checking other snippets on StackOverflow, in the WordPress category.