Looper and Query Strings

Hey guys. I am currently struggling with the Query String in a looper. I watched Josh’s video about sorting with URL string parameters and tried to adapt it to my case - without luck (and I think it’s a general understanding issue)

Basically I have a custom archive that needs to pull all posts from a certain post type. These need to be ordered by a meta key (new to old). On top of all the posts, I need a “filter” - meaning that I want a dropdown (or individual buttons) to only show posts from a certain category (acf meta field).

Now - my understanding is that I can build a query like this:

post_type=kunstwerk&posts_per_page=-1&meta_key=kunstwerk_kategorie&meta_value=gemaelde

I tried to use this as a base to test the general function and later exchange the meta value by a url string. But already now it won’t pull all the posts with the key “gemaelde” so I’m stuck. I don’t know if there is a syntax error in my query or something else is wrong.

Also - I find it hard to understand how to build these query strings (I don’t know php). They do make sense to me once I understand the relations. But is there any resource about how to write a query string, what the relations are (e.g. meta_key/meta_value) or is there a way to use the query builder in Cornerstone and have the string somehow be output or grab it from somewhere to use it as a reference?

Thanks guys!

Umberto

Hello,

Pro 6.4 has support for Meta Queries, try starting there since I don’t think you need to use a query string in this example. The docs are behind in this regard on our end, but it will look like this. It will also make sure you are using a valid meta key.

image

This site can also help you build the query string. Your string looks fine to me at the same time, so I would guess the meta key is wrong or the values are not set.

Happy holidays!

Hey Charlie!

Thanks for the pointer. However - I did play around with that but it didn’t work. In ACF Pro I have the meta “kunstwerk_kategorie” defined and it appears in the list in Cornerstone. However - when I put in one of the values (e.g. gemaelde), it doesn’t pull all posts from this category. I tried it with various values but nothing…any other idea what could be wrong?

I think I found the problem. I put “equal to” as the comparison. And it doesn’t work. If I put “like”, it does. Is there a misunderstanding on my side or is that something that needs to be fixed in cornerstone?

Also - another somewhat related question (I hope that’s ok) - now that I got the base to work, I am putting the dynamic content in the meta value and I wanna pass a url string. Can I have the fallback to load all values from that meta key? a * doesn’t work

Hello @umbertofederico,

It is best that you check out this documentation to know the difference when comparing the custom meta fields:

Thanks.

Awesome! Thank you :smile: happy holidays to you guys!

1 Like

You are most welcome @umbertofederico

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