Same slug for different CPT

[ad_1]

So currently I have created two CPT for my site. I want the url to be same. For example home.com/slug/title. SO the only thing i want to change here is the title for both my CPTs I want the slug to remain same.

The problem i am facing right now is, I created my own CPT for pages and another CPT for products catalog. So both needs to have same slug like brand/pagename and brand/productname. Something like this, How will i go around creating this? Creating two cpt with rewrite slug obviously is not working cause it will only work for one page. Since i have like 200 product catalog i need to put it separately since i am importing product from a csv file and using acf to create the product catalog page.

Any ideas ?

[ad_2]
2 Comments
  1. The best bet would be to write a method or simple plugin that uses `pre_get_posts` to hook into the query of the page.

    Don’t quote me, but I’m fairly sure the hook should work for single post and not just an archive.

    Talking in pseudo code, the process would be:

    1) Confirm the current query is for either post type A or B

    2) Confirm the query is taking place on a `single` template

    3) Check for the post in post type A

    4) if the post doesn’t exist in PT A, check PT B.

    [https://developer.wordpress.org/reference/hooks/pre_get_posts/](https://developer.wordpress.org/reference/hooks/pre_get_posts/)

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer