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]
- How to correctly edit permalink structures for both default and custom posts/taxonomies?
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Taxonomy, Terms, and Template Files
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- Adding meta values to permalink
- Hierachical Custom post types permalinks not working
- Custom Posttype Inheritance (and url structure)
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- Can you have two CPTs with the same permalink structure?
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Custom taxonomy & post slug permalink
- remove post-name from title in custom post type
- how to use two permalinks for one custom post type
- Custom Taxonomy List links being re-written
- Custom Post Types, Custom Taxonomies and Permalinks ?
- Custom Permalink Tag breaks Pagination
- Custom Permalink with Dynamic Taxonomy for Custom Post Type – Works, but breaks other permalinks
- Custom post type hierarchical permalinks not behaving as expected for parent/child pages
- removing custom tax & CPT slug, adding taxonomy term in front of custom type
- Custom post type and taxonomy permalinks – Structure
- CPT posts listed by category with custom rewrite URL, please help!
- Custom Post Type and Custom Taxonomy Permalinks
- Fetch ID’s associated with a custom post type when translated with WPML?
- remove permalink “front part” for custom post type
- Query var removed after rewrite
- Change Permalink Structure for Tag.php template
- Remove post type slug of all post types from permalinks
- Making a custom help center page
- Add archive slug to default post post type
- add category name to permalinks on product page /category-name/product-name
- WordPress add_permastruct unwanted matches
- Permalink for a custom post type isn’t working and I don’t know why
- Add custom post type settings to wordress default posts
- Assign same parrent Page to pages AND custom post types
- Query Post Object in WP Admin
- Custom taxonomy returns 404
- Removing Custom Permalink Structure for Custom Post Type
- permalink /category/post-name with custom post type and taxonomy
- Flush Rewrite Rules when new site is created on network
- Pretty URLs and custom post types
- Custom Post Type – Duplicate Page Slugs
- Remove permalink for custom post type
- Best way to specify “article type” in URL
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- Custom Permalinks with meta value not working. Why?
- custom endpoints on Custom Post Type return 404 page not found
- Post type Permalink
- How to display wp_post by custom field value?
- Custom Post Type with Configurable Sidebar via ACF
- Setting a homepage – doesn’t seem to work
- Improve Custom Post Permalink Structure
- Passing variables through permalink structure in custom post types
- Using page title as a link to term archive
- Pagination does not work on Custom Post Type archive while trying to get load more function working
- Custom post type items open in archives?
- How to mass get post editor URLs
- Error 404 change permalink term custom term taxonomy
- WordPress URL rewrites using Advanced Custom Field
- Custom post type defaults to index.php for archive page
- Adding categories to custom post type in permalink
- Pretty permalink structure with multiple (AND OR) taxonomies
- Remove wp directory and slug for custom post type from the URLs
- 404 custom post type
- Custom post URLs
- How can I add a “fake” parent into the permalink?
- Custom Post Type Archive Links Not Working
- Add category slug as class attribute in a link array
- Category slug not showing for Custom Post Type
- Get post id of permalink for a specific custom post type?
- URL Rewrite Adjustment for Custom Post Type causes template to revert to index.php
- Add taxonomy to custom post type archive
- Why are my wp urls showing page not found?
- Sorting custom post types by taxonomy (So close)
- Custom Post Type – Rewrite slug [duplicate]
- Custom Post Type Permalinks with %category%
- Custom post type – permalink
- Permalinks Works for Custompost type but not with pages Why?
- Custom post types permalinks not working
- Rewrite rules for using the same base slug for multiple content types
- img src not working correctly in custom post type
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Have Custom Taxonomy Slug Fall Under Custom Post Type Slug
- How to get the proper category in permalink with custom post type assigned to multiple categories
- .HTML POST extension for custom post type – DRAFT – PREVIEW