2

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:

  1. Recipes 1-3 (CPT "a") with URL: "home/%posttype%/%category%/"
  2. Recipes 4-10 (CPT "b") with URL: "home/%posttype%/%category%/"
  3. 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!!

0

I did look at your code and saw you changed the original code.

To make it more clear what you can achieve with this snippet. You would end up with the following permalinks:

/recetas-argentinas/category/desserts

Shows all post with the post_type recetas-argentinas and with the category desserts.

/recetas-argentinas/my-single-recept-post

Shows a single post of the post_type recetas-argentinas.

I did just use the code snippet from the original link and it was working for me.

Here is a screenshot of the rewrite analyzer to show how it works. Basically you enter a URL in the input field on the top and the plugin will show you which rewrite-rules will be matched by this URL:

Showing usage of Monkeyman Rewrite Analyzer

Also please be aware that the Category base in your permalink settings also has a influence to this. To have a permalink structure like above you would have to leave it empty.

Hope this is helping you to reach your target.


Old answer

Not sure I totally get your question, but from the following two sentences:

I've managed to use WP_query to create a page template [...] However, I can't figure out the URL structures or slugs for this filtered category archive

A page template doesn't have a permalink-structure. It's nothing more then a template assigned to a single page - even if you use it to display a "archive like" list of posts.

Two other suggestions:

  • For any rewrite problems (especially if it's about conflicting rewrite structs) it's a good idea to debug your permalinks with the Monkeyman Rewrite Analyzer.
  • register_post_type() has extensive support for creating custom permalink options which can help you avoid permalink conflicts.

Even if this is no direct answer to your question, I hope this is helping you somewhat further.

  • Thanks for the suggestions. I know my question is confusing, probably because I am confused myself. – user3784685 Jul 1 '14 at 4:56
  • Oops...hit the return button too quick! At the moment, don't have any conflicting slugs because I have just been testing things. I am also aware of the need to flush permalinks if I make any rewrite changes. However, let me try and clarify my question... Essentially, I want 3 views of the same content. I have been able to achieve this using wp_query in a custom page template. But I haven't been able to get the URL structure I desire for these 3 views. – user3784685 Jul 1 '14 at 5:06
  • If I have 10 dessert recipes, I want to be able to view them the final ways: 1-3 on one view 4-10 on another 1-10 on a third //this one being the standard category archive My approach for the content is to use 3 different templates, but this may not work with the desired URL structure I mentioned in the question post. – user3784685 Jul 1 '14 at 5:11
  • One more thing! I also found this: wordpress.stackexchange.com/a/135320/54882 which appears to be an even better approach than my wp_query option because the way I interpret it is that it takes care of both the URL structure and the desired content at the same time. However, I could not get it to work. Maybe I am missing something simple, but I copied the code into my functions.php file, flushed the permalinks, and tried to visit mysite.com/argentine_recipes/category/desserts or mysite.com/argentine_recipes/desserts and it didn't work. Got redirected to a single post and then got a 404 – user3784685 Jul 1 '14 at 8:30
  • That question really seems to be what you are searching for. Hard to tell why it's not working for you. Did you try the debug plugin mentioned above? Is the permastruct added to your global $wp_rewrites? – s1lv3r Jul 1 '14 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.