Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

Is there a way to query specific categories in genrateblocks query loop?

  • Hey all, so I’m trying to simplify work for my client as much as possible using pods.

    I’ve set up a pod custom post type, “product category” and a custom post type “product” that has a relationship with category. Example, client adds new product “product a” and it falls under product category “hand lotions”.

    I would love to be able to create a single loop template that loops over the categories products. So the hand lotions page only shows hand lotions, face lotion page only shows foot lotions, without having to make a separate loop each time, like “hand lotion loop”, “face lotion loop” etc.

    I’ve been looking but can’t find a solution, any help?

  • Hi there,

    You can use the block element – loop template, and enable the inherit-query-from-template option for the query block, and set the location to product category archives.
    https://learn.generatepress.com/blocks/block/query/#inherit-query-from-template

  • Ok, thank you. Where do I set the location from? I’ve enabled the option but can’t find that setting. It’s the first time I’ve used that option.

  • Where do I set the location from?

    The block element – loop template’s location is nested in the Rules panel:
    https://app.screencast.com/9d1phrAQsi0kl

  • Oh wait, yes I’ve done that, it’s one of the first things.

    Maybe I explained myself wrong. Basically I’m using the loop template and setting the location to the the all “Product Category” custom post type page..

    I’m trying to set a loop up so it only displays “products” cpt that are in that “Product category” cpt, but it’s always displaying all of them.

  • Basically I’m using the loop template and setting the location to the the all “Product Category” custom post type page..

    What is the exact location you set? Make sure you’ve enable the inherit-query-from-template option for the query block.

    And can you link me to a product category archive page?

  • Sorry, I wish I could, but it’s local.

    The location is “Product Category” “All product categories” it being a cpt.

  • The location you set is for single CPT, if you want it to be applied to the archive, try setting it to Product category archive instead.

  • Ok yes, done that, I had to enable archive in Pods settings.

    It’s not pulling in anything in the loop now.

  • I would need to see your CPT setup to know the issue.

    Let me know when the site is online 🙂

  • Ok, the site is already online as it is a client site which I’ve momentarily migrated locally to try this out.

    Would it be ok if I were to recreate the same thing on a temporary staging site on flywheel?

    You’ll need a username and password to see the site and I will send you wp-admin details.

  • Here you go, I’ve made a rough example with the same setup. Pods cpt “Product category”, pods cpt “Products”, bi-directinoal relationship. I have added two Categories and two products per category. The home page is displaying links to the category pages and there is a loop element set to the archive which I was hoping would display all products in that product category.

    Thanking you for any help!

  • Hey, sorry, just realized I accidentally add your admin to the local one. Too many tabs open hha.

    Added you to the linked site, same credentials.

  • I think you didn’t create the CPT correctly; the product category is created as a CPT, not a taxonomy of the product cpt.

    So the product category page is actually a single product category page, not an archive, that’s why there’s no default loop in that page.

  • Ok, thank you, I doubt It’ll work for what the client wants.

    On the original site I had set up a cpt for the three main categories and cpt for the main products. A hero in the home page that loops through the categories and links to the page and a gp element loop for each product type that is set to the page. The categories were supposed to only be three so I thought this would be an easy way for them to add/change products and change slider image/descriptions without having to play with blocks and plugins.

    But now they’ve asked if they can have a “duplicate button” on the categories in case they want to add new ones and have it all automatic.

  • You need to set up your structure correctly first. Then if you need help with GP or GB, let me know!

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.