I was wondering if it is possible to change the permalink of a cpt post to match another cpt’s permalink structure?
I have 2 cpt:
– programs (which contains some videos)
I have 2 fields in “videos”:
– is this video part of a program?
– if yes, which program
permalinks for videos are /videos/my-video, and programs is /programs/my-program
If the 2 fields in videos are properly set, is it possible that the video permalink becomes /programs/my-program/my-video ?
You need to add a custom permalink structure. The last time I did this I used this as a guide https://1fix.io/blog/2016/02/05/parent-from-another-cpt/
You’re basically going to be making one CPT child posts of another CPT. You can use a post object field for this in the same way that the parent is used in the document above.
In step 4 of the document you would set the permalink based on the settings of the fields.
Unfortunately you’ll need to to some testing and digging because I have only done this to make all of one post type the child of the other and the permalink is always altered. I do not know what extra steps you’ll need to take to make it not do it for all.
Thanks! Yea I’m not sure how I can modify only *some* permalink of a cpt and not all of them
I would try it as is and see what happens. I have an if statement that looks at the parent post and alters the url based on that setting. But I am not altering it if there is not parent post. On the other hand because of other things that I’ve done it is impossible to not have a parent.
Another thing is that something like that would be ran everytime the page loads, right? Isn’t it a problem to run permalink on every page load? Maybe I could only trigger it in the backend on save.
honestly, I don’t know, my filters run on every page load but I no not think that matters. When I make a change I have to do an update on the permalink settings page to make them effective. It is the only way that I know of to change the permalink of a post.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.