Here is what I’m trying to do:
I have 10 total dessert recipes (in shared dessert category) that are divided by 2 custom post types. I want to create 3 different views of these posts with the custom URL structure described below:
- Recipes 1-3 (CPT “a”) with URL: “home/%posttype%/%category%/”
- Recipes 4-10 (CPT “b”) with URL: “home/%posttype%/%category%/”
- Recipes 1-10 (all CPTs) with URL: “home/%category%/”
I have searched far and wide for an answer that completes both the URL and content aspects of my goal, but everything I’ve tried only addresses one or the other.
For example: For the content, I’ve used get_posts()
parameters to view specific category and post type, but since the template is assigned to a “page” the wordpress generated URL does not include the custom post type and the result is:
home/%pagename%/
For the URL, I’ve tried to use the init action to modify rewrite rules as suggested in this forum here and although this creates a URL structure exactly as I want it, the content output for the URL does not match what would be expected. The result is that all three URLs have all 10 recipes (essentially the general category archive page):
“home/%posttype%/%category%/” is the same as “home/%category%/” and I can’t figure out why.
I’ve also added a filter to pre_get_posts
to include my CPTs in the main query so that they show up at all. Not sure if there is a better way to do this in case it is interfering with the URL rewrite, although considering I took the code from the WP codex here under “Custom Post Types in the Main Query” I think the problem/solution is somewhere I don’t seem to be looking.
I can’t imagine that what I want is supposed to be that complicated. Can anyone see what I’m missing?
Thanks!!