Jump to content

Issue using OR in selector with Page->Closest method


MarcC
 Share

Recommended Posts

Hi everyone,

I'm having an issue where a selector doesn't seem to be working properly with page->closest. Here is the code: 

// Look for the closest page with any social URLs filled in
$page_with_socials = $page->closest("extra_url_1|url_5|extra_url_2|extra_url_3|extra_url_4!=''");

if ( $page_with_socials->id ) {

	// We found a page with social fields containing some URL content
	$social_config = $page_with_socials;

} else {

	// Fallback: Use home page social URLs
    // This is used every time extra_url_1 is empty, even if the other URL fields are filled out
	$social_config = $homepage;

}

Instead of checking the various fields, the selector is treated like it only says this: 

$page_with_socials = $page->closest("extra_url_1!=''");

In other words, it's like the other fields aren't even checked for content. If url_5 is filled in, or not, it doesn't matter. The else-fallback is always used as long as the other field, extra_url_1, is empty.

So I'm wondering--do I need to change the way I'm using the pipes in my selector or something? Thanks for any tips.

Link to comment
Share on other sites

On 11/24/2021 at 11:17 AM, MarcC said:

In other words, it's like the other fields aren't even checked for content.

I can confirm this. It's like the order of the field names is treated as if they are in order of priority, but I don't think this is expected - all the fields in the OR condition should be treated equally. Could you please open a GitHub issue so Ryan is alerted? https://github.com/processwire/processwire-issues/issues

  • 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

  • Recently Browsing   0 members

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