# Using Post ID in Listing URL

**URL:** <https://community.hivepress.io/t/using-post-id-in-listing-url/9661>\
**Category:** HivePress\
**Tags:** code\
**Created:** [February 10, 2024, 6:27am UTC](https://community.hivepress.io/t/using-post-id-in-listing-url/9661 "2024-02-10T06:27:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taxidermysocial](https://community.hivepress.io/user_avatar/community.hivepress.io/taxidermysocial/32/8715_2.png) [@taxidermysocial](https://community.hivepress.io/u/taxidermysocial)\
**Post date:** [February 10, 2024, 6:27am UTC](https://community.hivepress.io/t/using-post-id-in-listing-url/9661/1 "2024-02-10T06:27:43Z")

</div>

Continuing the discussion from [Unique number or ID](https://community.hivepress.io/t/unique-number-or-id/1339/13):

> [@Unique number or ID](https://community.hivepress.io/t/unique-number-or-id/1339/13):
>
> If you mean adding listing IDs to their URLs please check the available options in Settings/Permalinks. These are WordPress-level settings, I also found this solution (listings are implemented as “hp\_listing” post type) [permalinks - Put post ID on the custom post type URL - WordPress Development Stack Exchange](https://wordpress.stackexchange.com/questions/369343/put-post-id-on-the-custom-post-type-url)

```auto

// 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?

---

<div class="post-metadata">

**Author:** ![ihor](https://community.hivepress.io/user_avatar/community.hivepress.io/ihor/32/5_2.png) [@ihor](https://community.hivepress.io/u/ihor)\
**Post date:** [February 12, 2024, 11:05pm UTC](https://community.hivepress.io/t/using-post-id-in-listing-url/9661/3 "2024-02-12T23:05:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://community.hivepress.io/user_avatar/community.hivepress.io/system/32/13990_2.png) [@system](https://community.hivepress.io/u/system)\
**Post date:** [March 13, 2024, 11:05pm UTC](https://community.hivepress.io/t/using-post-id-in-listing-url/9661/4 "2024-03-13T23:05:32Z")

</div>

Closed on March 13, 2024, 11:05pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
