Jump to content

$pages->get("/features")->find("field1<field2") possible?


dotnetic
 Share

Recommended Posts

Hi,

is there a solution to get all pages from my folder "features" where "field1" is smaller than "field2"?

Is this possible with the find API? I tried it, with

echo $pages->get("/features")->find("field1<field2");

but it did not work. Any suggestions how i can achieve this?

Thanks in advance.

Jens

Link to comment
Share on other sites

The post isellsoap linked to above has Ryan's explanation on why it's not straightforward to compare two fields - and yes, there's a solution also. But I'd like to propose another solution as well in case you'd need better performance or native pagination (lots of pages for example).

You could add a helper field "f1_f2_difference" and populate it on page save with the difference of field1 and field2 (field2-field1). Then you'd be able to do this:

echo $pages->find("has_parent=/features/, f1_f2_difference>0");
 

There's an example of pretty much the same thing in the final post of this thread and for some more information read also this thread.

But you've got a working solution already so there's probably no need to take this route :).

--

@adrian: your suggestion would be fine when the fields are in the same database table (like created and modified are). Here field1 and field2 are presumably custom fields and thus in their own tables. An SQL JOIN would still do it, but using selectors gives the advantage of grants and visibility being taken care of.

  • Like 3
Link to comment
Share on other sites

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
 Share

×
×
  • Create New...