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 Display Content from Search URLs on Permanent URLs in WordPress?
- How to correctly edit permalink structures for both default and custom posts/taxonomies?
- Post ID randomly printing on page
- Change custom post type permalink to show name of post from another custom post type?
- Custom Post Type Permalink
- WordPress randomly shows 404 errors
- Permalinks for custom post type
- How to have this permalink structure: post_type/postname/custom_inner_page
- Additional section in custom post type permalink
- How to include term custom meta into the custom taxonomy term permalink structure
- Blog posts for custom post type only
- Path to custom post type
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- non-hierarchical post type with hierarchical url structure
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- Permalinks: custom post type -> custom taxonomy -> post
- Custom post type archive pagination 404
- CPT’s with landing page instead of archive – Url Rewrite?
- How to change permalink to include custom post type
- Removing Custom Permalink Structure for Custom Post Type
- Custom post type, permalinks, taxonomies and blog posts
- Custom post type permalink tag 404
- Custom post type permalink returns 404
- Use the same date-based permalink structure for all post types
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- permalink /category/post-name with custom post type and taxonomy
- “Post name” permalink returns home page for custom posts
- Custom post type and taxonomy permalinks
- Hierarchical permalinks for custom post type and taxonomy
- How to organize hierarchical structure in custom post type with taxonomy (like with categories)
- Make custom post types and pages place nice, re: rewrite
- Custom Post Fields at the beginning of a Custom Permalink
- Flush Rewrite Rules when new site is created on network
- Pretty URLs and custom post types
- Form action doesn’t work if slug isn’t same as custom post title
- How to make permalink structure %category%/%postname%/ work for custom post type?
- set permalink for CPT
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Lost of query parameter when using permalink
- Custom permalinks rules don’t match and lost of query var in the process
- Custom Post Type – Duplicate Page Slugs
- Taxonomy in URL
- Rewrite rule for Custom post type Monthly and Yearly archive
- Different results between permalink and query var search
- Best structure / rewrite rules to achieve the following url
- menu link to custom post_type?
- Custom permalink with child taxonomy terms
- Custom post type Permalinks with hierarchical Taxonomies
- 404 in custom post type feed with mistake permalink
- Retrieve post ID from “querying” URL
- Add a permalink variable onto custom post type URL after post name slug
- CPT category hierarchy
- Remove permalink for custom post type
- Permalink misbehaving in Custom Post Types
- Check post on publish for blank title
- Create Custom Post Type as page
- How to solve this custom post type goes to 404 page?
- Best way to specify “article type” in URL
- Template files for Custom Post Type and Taxonomy
- How to Create Template File for Parent Page of Custom Post Type
- How do you create %post_type%/%postname%/ permalink structure?
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- Changed permalink structure of CPT – should I redirect?
- How to query 2 custom post types that need to share a slug?
- Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
- I’m having trouble getting the permalink sample on my custom post type edit page to work
- How to change path for default WordPress blog posts?
- How to hyperlink content from archive page with custom post-type
- Can’t use pagination with custom taxonomy
- Custom Permalinks with meta value not working. Why?
- Custom post type as child of page
- Remove custom permalink structure from custom post type without modifying register_post_type() directly
- How to have permalink like domain.com/term/postname?
- Can variables be used to rewrite a Custom Post Type permalink? [duplicate]
- make permalink go to a custom single.php file
- Custom post type permalink sends to 404.php
- Post will not load via ajax
- How does: /index.php?post_type=event&event-date=2011-07-25 work? What if it doesn’t work?
- Template for custom post type when taxonomy is in the URL
- One Custom post type 404’s others don’t
- 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
- Permalink problems with custom post type and custom taxonomy