1

This works:

            {% set entries = craft.entries({
                section: 'listing',
                listinglatitudenumber: '>=' ~ pluginResults.latmin
            }) %}

But I need to do this:

            {% set entries = craft.entries({
                section: 'listing',
                listinglatitudenumber: 'and', '>=' ~ pluginResults.latmin, '<=' ~ pluginResults.latmax
            }) %}

And I cannot for the life of me figure out the correct syntax for this.

I have been trying many different combos for the 'and' statement based on other answers I have seen in the Craft Stack Exchange but have not been successful. I have not been able to find any docs on this type of query.

Any help much appreciated :)

ironfish
  • 141
  • 5

2 Answers2

1

You need to separate your criterias with commas

listinglatitudenumber: 'and, ' ~  '>=' ~ pluginResults.latmin ~ ', <=' ~ pluginResults.latmin, 
Robin Schambach
  • 19,713
  • 1
  • 19
  • 44
  • Thanks Robin once again for your help :) With the above syntax I get:

    Internal Server Error

    A hash value must be followed by a comma. Unexpected token "string" of value ", <=" ("punctuation" expected with value ",").

    And I am trying to understand exactly what you mean, and trying to resolve the error, but not successful - could you explain further?

    – ironfish Apr 22 '18 at 19:44
  • Of course you need to place a last comma since you are inside an object. Please read this https://craftcms.stackexchange.com/a/25774/5557 you can either separate your values via comma or you use an array from the beginning – Robin Schambach Apr 22 '18 at 19:56
  • Thank you I will look at the examples and try to get it working :) – ironfish Apr 22 '18 at 20:08
  • Let me know if you need further help. You simply need to convert PHP string separators . with twig ~ – Robin Schambach Apr 22 '18 at 20:09
  • Thank you Robin again for your time and effort on this. :) – ironfish Apr 22 '18 at 20:26
  • Hi Robin, At the time you provided your answer using commas, I was not able to get that to work and so I found another way to do it using [ ]. I now see that using commas would also work - I did not mean to diminish your answer. Thanks again. – ironfish Jun 09 '18 at 17:12
0

As per: Query entries between two values I found that enclosing the query string that I had with [ ] to make it a sub-array, works:

        {% set entries = craft.entries({
            section: 'listing',
            listinglatitudenumber: ['and', '>=' ~ pluginResults.latmin, '<=' ~ pluginResults.latmax]
        }) %}
ironfish
  • 141
  • 5