Help with Queries

I created a project portfolio using the Portfolio custom post type built into Pro. I used the layout builder to get the look I want on the project category pages and single portfolio item pages. The goal was for it to be easy for the client to add new projects and it was working great until they changed their mind.

Here’s an example of an existing category page the way we set it up. As you can see, this shows all their grocery store client projects.

They now want the category page to show only one item from each client project. For those that have multiple projects, they want those to link to a subcategory/archive page of all those projects. For those that have just one project they want it to link to the single for that project.

I’ve been racking my brain trying to figure out how to do this. Is there a way to use query string url parameter or segment with a fallback so that if there’s a subcategory it links to the subcategory and if there isn’t, it links to the project single?

I’ve already figured out how to have only one project on the category page by selecting only one portfolio item in the parent category and adding the rest to the subcategory. But I can’t figure out how to create the conditional url, if that is even possible.

Hello @toddbenton,

Thanks for writing in! What you have in mind may be accomplish depending on the relationship between the category, project and the clients. Did you added custom fields? Or you just simply use tags and categories? To better assist you with your issue, please provide us your WP credentials first so that we can analyze the data structure of your custom post type. You can create a secure note in your next reply with the following info:
– Link to your site
– WP login URL
– WP username
– WP password
– WP Administrator Role
- Confirmation that we can access and make changes to your site

To know how to create a secure note, please check this out: How The Forum Works

Best Regards.

Secure note added. Thanks for looking into it.

Hello @toddbenton,

I have checked your custom archive layout and I found out that you have added a Looper Provider. Please be inform that when you are doing a custom archive layout, you do not need to use Looper Provider. All you need is a Looper Consumer because the archive itself has its own WordPress Loop that generates the contents dynamically. As a matter of fact, you can have 1 custom archive layout and this layout will display the respective category archive page with the correct items in it.

I have check your Projects as well. They only share a category.

They have the same Project title and only differ on the slug, {project-title-locationof the project}. If you want them to have a subcategory, those projects must be assigned to the sub category as well.

Hope this makes sense.

If I were doing blog posts and wanted them ordered chronologically, then I would not have used the looper provider, just the looper consumer. But if I want to do more complex filtering, that’s not offered at the consumer level, right? A looper consumer only gives me All, One or Many. So, regarding the first part of your comment, that’s why I used a Looper Provider. That way, I could use the Query Builder and order by Title/Ascending. To answer the questions in your first response, I simply used categories only. But I could also use tags if necessary.

You’re correct, I had not gotten to the step of creating the subcategories yet, because I wanted to know how I should go about doing that given what I explained in the original post.

Hello @toddbenton,

The page, https://example.com/project-category/{name}/ is a category archive page and WordPress will always display in chronological order. You do not need to filter out the returned items because WordPress will always display project items that is assigned to the category {name}.

If you use a Looper Provider here hoping that the project items will display in alphabetical order, it will give issues later on like that pagination will never work because the Looper Provider resulted an issue that confuses the pagination.

The correct way way of alphabetizing the items were explained in this codex:

Hope this makes sense.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.