Maybe I’m missing something, but you seem to have missed one of the most ubiquitous functions in WordPress Core– get_permalink()
. The function accepts two optional parameters, the first of which is the post ID. So, to get the permalink via the post ID all you need is $perm = get_permalink($post_ID);
. If you just need to echo
the permalink you can use the_permalink($post_ID);
instead.
As for “something like” echo home_url() / post_type / post_name
, you don’t really get to choose the permalink structure ad hoc like that. It won’t work. WordPress Core won’t know how to process the request. You will have to configure your permalinks to match that pattern then the functions above will generate them appropriately.
Related Posts:
- Add .html (dot HTML) extension to custom post types
- Change the url of Projects in Divi Theme
- Get a permalink structure of /%posttype%/%category%/%postname%
- How do I get the permalink structure to work like this?
- Bizarre Permalinks Issue: 404 Errors Everywhere
- Custom Post type and permalink settings
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Preview url not working outside wp-admin
- CPT – Custom Text fields point to new url permalinks
- Custom post type with parent page? Possible?
- Get full control over custom post type url
- How to switch from custom post type URL to category URL?
- Custom Post Type Categories Not Maintaining URL structure any more
- Hide custom post type slug url from search engine [closed]
- Shouldn’t this be easy?! Custom post type/custom taxonomy permalink
- WordPress 3.3 custom post type with /%postname%/ permastruct?
- Custom Post type & Taxonomy URL structure
- Combining Multiple Taxonomies in one URL
- Taxonomy term in permalink
- How to give a CPT (custom post type) a date based url
- Custom Post Type Archives by Date with Custom Permalink
- Why does a custom post type need the ”hierarchical’ args setting?
- Modify custom post type rewrite rules in a separate function
- Slug for custom post type archive
- Permalink rewrite with custom post type and custom taxonomy
- Permalinks in Custom Post types
- Custom Post Type with Nested Taxonomy and Template Files
- Semantic URL Custom Post Type and Taxonomies permalinks
- Disable WordPress Recognizing Path as Attachment
- Passing parameters to WordPress static front page
- How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?
- How to detect filter in URL in Category page?
- Wrong generated page_name/slug on first publish of custom post type
- Stop / prevent WordPress from updating permalinks of custom post type
- How do I correct an incorrect permalink?
- Update permalinks when new category added to custom post type taxonomy
- Tag Archive for Custom-Post-Type Posts yielding 404 when permalinks set to postname
- Allow post/page hierarchy across different post types?
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- custom-taxonomy/post_name instead of the default post_type/post_name
- Custom Permalink to remove category word , keeping posts permalink with date?
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Custom Post Type Permalink
- Permalinks for custom post type
- How to include term custom meta into the custom taxonomy term permalink structure
- Custom Post Fields at the beginning of a Custom Permalink
- Permalink misbehaving in Custom Post Types
- I’m having trouble getting the permalink sample on my custom post type edit page to work
- Custom post type permalink sends to 404.php
- Post will not load via ajax
- Template for custom post type when taxonomy is in the URL
- Custom Post Type posts, conflict with posts after add_rewrite_rule to top
- How to change base in tag URL for custom post type, to not use “Custom Structure” set in Permalinks setting?
- Combine multiple CPT names to create valid permalinks
- How to add a sub directory to WordPress single posts without affecting other post types?
- How to create custom search result page with custom URL parameters for custom post type?
- Which is the neatest way to have homepage articles and a blog?
- Custom Post Type URL Rewrite’s
- Custom rewrite rules for /pastissues/%category%-%postname%.html
- Subpages Permalinks Issues
- Multiple permalinks for a single post with multiple taxonomies
- Stop displaying Permalink
- Permalink with hierarchy of Custom Post Types
- Rewrite URL for CPT to domain/post-name/post-id
- Custom Endpoint For Specific Custom Post Type
- How do you create pillar content pages?
- Custom permalink structure for custom post types including multiple taxonomy
- Custom post type single page returning 404 error when sharing archive url with custom taxonomy
- Modify Url for Edit Post Screen in Custom Post Type
- Customise Permalink Structure For Custom Post Types
- How to make “single post” permalink maintain it’s sub-page structure
- Two and more diffrent custom page type in one permalink
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- Page as parent for CPT and other pages
- How to display a custom post as a page (but unedited)?
- Two CPT: one is using part of the custom rewrite slug from the other
- Unwanted URL with Custom Post Type
- Change the url of a custom post type to include taxonomy
- how to use two permalinks for one custom post type based on categories
- Can I override the permalink/slug on creation
- Multiple custom post type and permalink issue
- Permalinks when using Custom Post Type with static page for archive
- How to change permalinks to taxonomy and post type’s posts
- Have two (permalinks) urls for a same custom post type
- change precedence of permalink for post_types?
- Redirect permalinks after creating custom post types
- Parent cpt/child custom post type URL permalink relationship
- How to make nested custom post type slugs work
- Custom Post Type Permalinks Problem
- Problems with custom post type and hierarchical permalinks
- Cannot get query var ‘post_type’ to work
- Custom Post Types and 404 Pages
- create gallery page for specific post id
- Remove slug from Custom Category Permalink + dual-category permalinks
- WordPress Set A Static Page/Template For All Sub-Pages
- Links in archive not including taxonomy parameter
- Get permalink in custom post type loop doesn’t work
- Custom post type with custom parent prefix slug
- Is it possible to use a post name in a custom post slug?