Jump to content

selector for pages with images > 2


seddass
 Share

Recommended Posts

Hi all,

Is this possible with PW selectors? I am trying to fetch the children pages with more than two (or any other integer) of uploaded images. Was trying it with something like that but still without success:

$children = $page->children('images>2');

Does anybody have a quick answer?

Thanks.

Link to comment
Share on other sites

I've got an update for you in 2.1 which makes this available. I'm going to run it through a little more testing tomorrow, and if all checks out I'll commit this to the 2.1 source.

Link to comment
Share on other sites

Okay good news, this is now available in the latest commit of 2.1:

https://github.com/ryancramerdesign/P21/commit/da6418cedeede89b7039341536641e5080fea144

To use it, you have to add a ".count" to the end of your field name. Using your example from above:

$children = $page->children('images.count>2'); 

The reason you have to use ".count" is because without it the operator is comparing the image's filename. While I could redirect the ">", "<" and related comparison operators to the count, I wanted to find a consistent way to do this throughout the system, and adding ".count" to the field name seemed the most logical way to do it.

You can use this with any multi-value field: files, images, page references, comments, etc. You can also use it with a page's children, i.e.

$children = $page->children('images.count>2, children.count>0'); 

Note that all pages have a 'children' property, so it can feasibly match any page. But maybe not all pages in your system use a template with the "images" field. PW doesn't attempt to match pages that don't even have the field, so if you did this:

$children = $page->children('images.count=0'); 

...that will only match pages that have an images field with zero images. It won't match pages that don't have an images field. This is for consistency with other selectors.

Please let me know how this works for you and/or if you run into any errors with it.

Thanks,

Ryan

Link to comment
Share on other sites

Hi Ryan,

Great work as always. Thanks for the improvement, this simplifies the work with PW and makes it more enjoyable. 

It does make sense using ".count" and it is more human friendly than using only the field name.

In the first tests It is working flawless, as expected. Will report if there are related issues.

Thank you,

Alex

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

  • Recently Browsing   0 members

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