1.I have a custom post type called “products”
2.I have a custom taxonomy called “itemcategory” that is assigned to the CPT “products”
3.any product post have a (acf) custom field “sku”. => the_field(‘sku’);
I want my permalink structure to look like this:
products/category/sku-field
or
/%custom-post-type%/%custom-taxonomy%/%sku%/
Stuck with it and need help
Thanks
There are 2 ways that I can think of to do this.
First the hard way
The first thing you’re going to need to do is to create custom rewrite rules https://codex.wordpress.org/Rewrite_API/add_rewrite_rule
The next thing you’ll need to do is create a pre_get_posts filter to alter the query based on those rewrite rules https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
And finally you will need to create a filter to alter all of the permalinks for the taxonomy or post type, whatever it is that %sku%
in /%custom-post-type%/%custom-taxonomy%/%sku%/
represents.
Then the easy way
Create an acf/save_post filter https://www.advancedcustomfields.com/resources/acfsave_post/ and in this filter get the value of the sku field and update the post slug to match this value. The problem with this is the you need to make sure that the value entered for sku is unique. I have outlined how to do this here https://support.advancedcustomfields.com/forums/topic/accept-only-unique-values/