Jump to content

Weird selector behaviour


muzzer
 Share

Recommended Posts

I have some sample pages setup, titles as follows

  • Adams page
  • Anitas page
  • Another page
  • Another page 2
  • Another page3

These all have parent id 29. I'm trying to get all pages with title starting with "An". So

$pgs= $pages->find('parent=29, title^=An');
foreach( $pgs as $p )
   echo $p->title 

This returns Anitas Page, Another Page, Another page 2, and Another page 3, which is correct. Adams Page is not included as it does not start with "An". Cool. PW makes this so easy!

 

However, if I alter the title selector to find page titles starting with just "A":

$pgs = $pages->find('parent=29, title^=A');

this weirdly produces Adams Page and Anitas Page. For some reason the other three pages are not returned. What??!

Am I missing something obvious with the ^= selector?

 
Link to comment
Share on other sites

Hi muzzer!

Did you already find out what was causing this odd behavior? I tried to reproduce what you're describing but I'm getting all those five pages returned with "title^=A".

I guess you tried both selectors with the exact same setup? So no chance you've got a limit of some kind somewhere?

You could also try those selectors with the SelectorTest module, just to eliminate other code lurking around. And with debug mode on try to find the actual database query for both (you can see all queries printed out at the bottom in the admin when debug is on). Maybe there's something there that helps finding the cause.

  • Like 1
Link to comment
Share on other sites

Hi nik,

Thanks for the response and for testing this on your system for me. I debugged the queries as suggested with the same weird result, number of rows returned confirming the above. I also installed the SelectorTest mod (which is damn sweet BTW) and no luck. In frustration I upgraded to PW 2.3 and problem sorted.

I see in the docs the ^= selector works in PW v2.1 onwards. I previously had 2.2 I'm sure, possibly 2.1 at oldest, as when I first started using PW ver2.1 was the current release. Anyways, guess this is a good example of the advantages of being up-to-date.

SelectorTest will be a must-have on all my PW site install from here-on-in. Very nice peice of work. Thanks nic

  • Like 1
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...