- Use
add_rewrite_tag( $tag, $regex );
to register a rewrite tag for the custom field. - Filter
post_type_link
to replace the rewrite tag. The second argument is the post object, so you have always access to the post ID.
For a sample implementation see my plugin T5 Rewrite. It does exactly that in the class T5_Rewrite_Tag_Custom
.
Related Posts:
- Adding meta values to permalink
- ACF Relationships in Custom Post Type Permalink
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- How to Display ACF Relationship Custom Field as Link to Specific Custom Post?
- Customize permalink when creating a post
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Show custom post type relationships by taxonomy
- Custom Post Fields at the beginning of a Custom Permalink
- Adding an extra parameter [string] to my posts’ permalink?
- CPT – Custom Text fields point to new url permalinks
- Orderby CPT custom fields not working
- Add custom post type settings to wordress default posts
- WP_Query order by custom field, then randomly order some of results
- A better way to add a meta box to custom post types
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- WordPress Custom Post Type Permalinks dynamic term slugs
- Rows with custom columns not well formatted after Quick Edit save
- How to have the same url structure for both a CPT and a Taxonomy?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- Plugin – Combine Meta Box Input Fields into single saveble record
- Two Custom Post Types Many to Many Relationship
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- custom-taxonomy/post_name instead of the default post_type/post_name
- Show custom post archive when custom post not specified
- get_post_meta not working on publishing
- Query custom post type with ACF Date
- Custom setting to show or hide field
- Custom Meta Field – Remove comma from string with str_replace
- Assign same parrent Page to pages AND custom post types
- Can’t remove front from permalinks for custom taxonomy category page
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- WordPress custom post type permalink rewrite shows page not found
- How to set a CPT to have a page as a parent, then rewrite urls accordingly?
- Completely remove custom post type permalinks (“One Page” website)
- Using custom field content as expression in IF statement [closed]
- Meta Query Not Returning Output Despite Having Matching Values
- Using taxonomy term in CPT permalink – Pages 404’s
- How to create a custom post type with additional fields?
- Callback to custom field is not working in WordPress REST API
- Meta Query Filtering not working on Custom Meta Box using Radio Buttons
- Including metaboxes from custom post types in global search — continued
- Removing custom post type slug from URL
- ACF From & To Date Validations
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Custom post type as home page with custom url
- How do I set all of a particular post meta to a value within the custom post type I’m in?
- Query Multiple Custom Posts by Custom Fields
- Customize Custom Post Type URL
- Show image gallery from a custom field
- Using advanced custom fields from one custom post type in another custom post type / using nested shortcodes
- Dynamic dropdown select values depending on other custom field value
- How to render a custom post type template with custom fields using shortcode
- Create a custom php page and load it at a specific slug
- Disable saving posts as draft (make all posts mandatory regardless of the post status)
- Grouping metadatas into one
- URL rewrite add author as base
- Remove CPT name from permalink but add %category% instead
- Tracking changes in admin-page so user gets warning when leaving the page
- filter custom post in rest api with custom function
- Get Posts by multiple custom fields is not working
- Permalinks /country/city/cpt/postname/
- Custom Permalink to remove category word , keeping posts permalink with date?
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Seamless permalinks between Custom Taxonomy and Custom Posts
- Woocommerce custom field search in custom post type [closed]
- Custom post type and custom taxonomy with the same slug using the file page taxonomy only as directory
- Add custom field in comments form
- Need help with permalink rewrites for Custom Post Types with hierarchical relationships
- Custom Post Type Permalink empty
- Custom Fields for Custom Post [closed]
- Order Custom Post Type by Custom Field Value
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Filter custom post types by a field value
- Displaying All Posts of a Custom Post Type in WordPress Multisite Backend
- Change custom post type permalink to show name of post from another custom post type?
- Custom Post Type Permalink
- Repeatable Fields Metabox with Textarea (or wp_editor)
- How to use TinyMCE Editor for one of my custom post meta field?
- Permalinks for custom post type
- Custom REST endpoints for a custom post type with custom fields
- How to have this permalink structure: post_type/postname/custom_inner_page
- Additional section in custom post type permalink
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Hierarchy and access control for Custom Post Types (CPT)
- Custom fields (wp_post_meta) vs Custom Table for large amount of data
- How to include term custom meta into the custom taxonomy term permalink structure
- Blog posts for custom post type only
- How to integrate a form (Ninja Form or Contact Form 7) with Custom Post Types?
- Path to custom post type
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- First custom field value (out of several) displayed twice after query
- Homepage’s content is dependent on the custom field values (set automatically), how do I get homepage to update without manually updating page?
- Meta Query posts not showing on ending date of custom field
- Cannot save CPT meta box
- Cross reference custom post types
- Adding Page Templates to post but it ignored it
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working