Jump to content

Filtering pages where field value is greater than a negative number


Recommended Posts

Posted

Hello

I'm having an issue with filtering on a negative longitude value.

My search filter looks like this (decimal places have been shortened for the example)

$pages->find("template=skyscraper,longitude>=-0.1011,longitude<=0.0708,limit=10,sort=created");

Now lets say I have two pages, one has a longitude of 0.05, this one is found.

Another has a longitude of -0.05, this one is not found, even though -0.05 is still greater than -0.1011...

Posted

As always I work this out after 30 mins of trying, but always 2 mins after posting on a forum ?

It was because the field type must be float decimal, (see below!). Funnily enough it works fine if it's Text, until you hit a negative number. I will leave this up for anyone who makes the same mistake as me.

  • Like 2
Posted
7 hours ago, cst989 said:

It was because the field type must be float.

From past experience working with lat/lng coordinates, I suggest using a decimal field for these. Float fields only have a precision of 6 figures which is often not sufficient for a lat/lng value.

  • Like 2
  • Thanks 1
  • 1 year later...
Posted
On 11/22/2020 at 9:08 PM, Erik Richter said:

@cst989 Hey! I changed the fieldtyp to float in database, but still: as soon as I have negative longitude, I get no results.. any tips? Thank you!!!

Hi Erik, I would try the decimal fieldtype linked to in Robin's post - and also you don't want to be changing it directly in the db, just changing the field type

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...