Build query string looper based on category

Hi,
I am trying to build a query string to pull in posts by category based off of the CPT name.

So for example if my CPT post is called Fearless Records it should only show records with the category “Fearless Records” from CPT concord-albums.

This is the string I am trying:
category_name ={{dc:post:title}}&post_type=concord-albums

I tried finding a way to do it with query builder then adding conditions but could not figure it out.

Hi @wowflak,

Thanks for reaching out.
You need to use the {{dc:term:name}} or {{dc:term:slug}} instead of {{dc:post:title}} which return the title of the current post. Whereas {{dc:term:name}} or {{dc:term:slug}} return the Category name or slug of the current post, which need to be use in Query String to get the post based on the Caetgory.

category_name={{dc:term:name}}&post_type=concord-albums

Or

category_name={{dc:term:slug}}&post_type=concord-albums

Hope it helps.
Thanks

Thanks I have tried both like this:
category_name={{dc:term:slug}}&post_type=concord-albums&posts_per_page=12
category_name={{dc:term:name}}&post_type=concord-albums&posts_per_page=12

And they both return all posts in the CPT. I want them to filter by the Category, which I tried based on the current post name and slug and term to no avail.

To clarify this is a looper in a layout for the CPT “Label” I then want to pull in posts under the CPT “Concord Albums” based on the category it is in. So if the “Label” CPT is “XYZ Records” I want it to pull in posts from CPT “Concord Albums” that are tagged with category of “XYZ Records”

Does that make sense?

Actually got it to work like this:
category_name={{dc:post:title}}&post_type=concord-albums&posts_per_page=12

Hi @wowflak,

Glad that you are able to get it work.

Thanks

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