Support

Account

Home Forums ACF PRO Change permalink on Field selection with different CPT

Solving

Change permalink on Field selection with different CPT

  • Hey all,

    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:
    – videos
    – 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 ?

    Thank you!

  • 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.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.