You can access the post type properties using get_post_type_object()
. The rewrite argument will be a property if the returned object:
$post_type_object = get_post_type_object( 'products' );
$rewrite_slug = $post_type_object->rewrite['slug'];
Update
I needed this for permalinks inside a template part where there are categories displayed.
No you don’t. To get the URL to a category archive, use get_term_link()
:
<a href="https://wordpress.stackexchange.com/questions/364027/<?php echo esc_url( get_term_link( $category ) ); ?>" class="cat-bar__label"><?php echo $category->name; ?></a>
Related Posts:
- How to customize a permalink (URL) structure?
- WordPress Custom Post Types with a page as a parent?
- Custom post status not working
- Get custom post type by category in a page template
- Redirect after deleting post and keep track of pagination
- Remove POST_TYPE from custom post type permalink
- Error after deleting Custom Post Type with a function (no trash used)
- Row actions not showing? Why?
- How do I add a custom button to my “edit” list? ( edit.php?post_type= ) beside “Add New”
- How do you output custom code between posts in the loop?
- How to append element after thumbnail
- Dynamic Custom Post Type Plugin
- Custom Post Type | Fatal Error on register_post_type()
- Weird problem happening with custom taxonmy when creating/updating posts
- Admin notice not displaying
- Plugin: register custom post types, child ready and performance best practices
- Use custom metabox to update automatically a post after a given date
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Problems wp_insert_post and save_posts filter
- Redirect to another page using contact form 7? [closed]
- Show current custom taxonomy
- How to insert data into meta box from another plugin?
- How exclude or skip post type with get_next_post_link
- WordPress: Custom User Role cannot access Custom Post Type | “Sorry, you are not allowed to access this page”
- How do I add custom HTML to the content of an archive page’s posts?
- Creating a non-hierarchical Taxonomy that behaves like categories
- post_content is stripping HTML when adding a new post? [closed]
- Validate Custom Post Type fields
- Displaying One Custom Post Type’s Content On Single Post of Another Custom Post Type
- Convert Custom Table Data Based Plugin To Be Searchable
- Is there a (preferable built-in) way to check what custom queries are used in a theme?
- How do I ensure that post_type and Taxonomy use the same slug?
- Custom post type page with parameter
- Change Dropdown jQuery to show/hide but with default place holder that shows all
- How to show the post which checkbox is not selected
- Is it possible to get the specific content on the search page?
- Why is my custom post content only viewable when signed into WordPress?
- Auto update publish date of CPT Post if default post custom field value match to cpt post CF Value
- How can i display a taxonomy? i have created a plugin and then a custom type. and a taxonomy , also i have register it
- Plugin Development using classes – Public & Private Callbacks
- custom post type and user post count shortcode
- How to limit the number of custom posts certain users can publish in WordPress using php script?
- Having issue on Loading Meta Data From CSV to CPT
- Stored meta from attachment, video length?
- WordPress query posts by custom post type not workng
- How to display all custom fields associated with a post type – IN THE ADMIN AREA?
- Create 2-layered dropdown menus for custom taxonomy and custom post type
- Registering an optional custom post type from a plugin
- Add category slug as class attribute in a link array
- Add Excerpt On Quicksand Plugin
- Select Menu for Custom post Type does not save
- Multiple Block Quotes without using HTML
- How to apply order on custom taxonomy and custom meta key on custom post type
- Inserting two categories
- Set a Custom Post Type as a Homepage
- How to dynamically register custom post type
- How do I programmatically add items of content to a custom post type?
- Uploaded image not appearing in custom post type
- How to allow “Add New” capability of CPT when links to its UI are placed as a submenu?
- How to add notification in the sidebar of the administration panel when a Custom post type is created? [duplicate]
- How to get Custom Post ID by adding filter to child theme’s function
- Custom Post Type get_post_type_archive_link( $post_type ) returns false
- WordPress if in term*
- Custom post type permalink returns bad url
- WordPress theme custom capabilities not works
- How do i calculate the total of values of custom fields in custom post types?
- Custom post type – get_day_link()
- Meta query for custom post type ignored in main query
- Custom Path/Folder behind a custom post type
- get_post_meta not working on publishing
- Different Category system needed for the Custom Post Type
- How to display custom field value on page?
- How do you make a list and list item relation if custom post types?
- Removing full title and breadcrumb header container for a specific post type
- Using Pagination for Custom Post Type and keeps returning 404
- meta query not retrieving posts
- Is it possible to sort metabox teaxtarea values?
- CPT Repeatable Fields + Undefined Index
- foreach loop inside the loop creating duplicates in output
- CMB select with data from CPT
- Content in WP Editor displayed below CPT shortcode [duplicate]
- Custom Post Type Causes Error: Warning: call_user_func_array()
- Get only parent post in archive post
- update custom taxonomy custom fields
- Filter taxonomy by CPT
- Custom post type specific item design
- How can I assign multiple parents to CPT?
- Issue removing columns from admin table
- Tell wordpress to show a single page instead of an archive page
- WP REST API Custom endpoint don’t work in my plugin
- Limit posts per page depending on the size of a div?
- Delete Post by User
- Include images from pages in wp search.php results in default wp search
- WordPress loop add heading before first of type
- Can I override the permalink/slug on creation
- Custom Search not working
- Custom Taxonomy Showing in WP Menu
- Custom Post-type not returning the right child_of
- Hide custom post type and use its slug in new plugin menu
- Creating post custom field text area