Using Looper Queries to Display Portfolio Items with same Category

Hi,

I’m trying to make a Portfolio Page template that can display other similar Portfolio Items in the right column.

How can I use Looper queries to

  1. Look at the category (or categories) of the Portfolio Item
  2. Display Portfolio Items of that same category (or categories)

I hope I’ve explained this clearly.

Thank you!

April

For more context: It’s for items in this portfolio https://aprildoty.com/audiobooks/
I want people who read paranormal fantasies (like Blood Orchid) to see other paranormal fantasies when they are reading the Blood Orchid page.

Hey @aprildoty,

Thank you for reaching out. I understand you would like your Portfolio Item layout to show, in the right column, other Portfolio Items from the same category as the item being viewed. You can do this with two Loopers, one inside the other. Please follow the steps below.

Step 1: Quick Check

  • Confirm your PHP version is 8.1+.
  • Confirm both Pro and Cornerstone are updated to the latest versions.

Step 2: Troubleshooting

  1. Loop over the current item’s categories – In your single Portfolio layout, select the element that wraps the right column (for example a Div). Under Looper Provider, choose Current Post Terms and set the taxonomy to Portfolio Category (portfolio-category). Turn on Looper Consumer for this same element so it repeats once for each category. You can add a Headline inside it with More in {{dc:term:name}} as its text.

  2. Query the matching items – Inside that wrapper, add the element that will hold the items (for example another Div). Set its Looper Provider to Query String and paste this into the field:

    post_type=x-portfolio&portfolio-category={{dc:term:slug}}&post__not_in[]={{dc:post:id}}&posts_per_page=4
    

    {{dc:term:slug}} is the category from step 1, and post__not_in[]={{dc:post:id}} leaves out the book being viewed. Change posts_per_page to the number of items you want.

  3. Display each item – Inside the step 2 element, add the element you want repeated for each book (for example a Div holding an Image and a Headline). Turn on Looper Consumer for it and leave Rewind off, since Rewind on a nested Looper can make the page loop endlessly. Use {{dc:post:featured_image}} for the image, {{dc:post:title}} for the title and {{dc:post:permalink}} for the link.

Please note: if a book is in more than one category, it shows one group per category, so a title may appear in two groups. Giving each book a single main category keeps the list clean.

Step 3: Recommended Resources

Best Regards.