Jump to content

Negative selector with multi page field not working


gebeer
 Share

Recommended Posts

Hello all,

I read carefully through https://processwire.com/api/selectors/ but can't seem to get negative selector to work on a 2.4.11 install.

My setup:

-places with tags.

-"tags" field is a multi page select field.

When I do

$pages->get("/places")->children("tags*=food")

I get all children with tag "food".

But when I do

$pages->get("/places")->children("!tags*=food")

I get all children. But it should only return all children that do not have the tag "food".

The selector api states about negative selectors

Negative operators

You'll notice we have a != "not equal to" operator. That's great for numbers and fields where we know the entire value, but not particularly handy for large text fields. For example, this would not be useful:

body!=sushi tobiko

That would likely match all the pages in the site, unless you had a page that contained only the phrase "sushi tobiko" as the entire body field with nothing else in it. So that selector isn't useful, whereas, we can take a different approach to negate the result of any selector by simply preceding the field with an exclamation point "!", i.e.

!body*=sushi tobiko

This would match all pages that didn't contain the phrase "sushi tobiko" somewhere in their body field. Now that is useful.

So what am I doing wrong here? Might it be related to my tags field being a multi page select field?

What I'm ultimately trying to achieve is

$pages->get("/places")->children("tags*=food, !tags*=accomodation")

Cheers

Gerhard

Link to comment
Share on other sites

This negative selector is for textfields.

Also *= is for textfields.

Maybe you are lucky and "!tags.title*=accomodation" works.

Page fields work with ID's 

"tags=1233|1232" 

To search for a title within the selected pages you'd use a subfield selector

"tags.title=abc"

  • Like 1
Link to comment
Share on other sites

This negative selector is for textfields.

Thanks for the enlightenment. Didn't find this info in the api.

Also *= is for textfields.

It is working fine so far with my multi page select field. Both tags*="food" and tags.title*="food" are working as positive selectors. Might be because my tag template contains only the title field.

Maybe you are lucky and "!tags.title*=accomodation" works.

Unfortunately not :-(

I tried using the page id for "food" as a selector value. It is working for positive selectors only.

Butf I do

$page->children("!tags={$foodid}")

it lists all children again.

What would be a workaround to achieve

$pages->get("/places")->children("tags*=food, !tags*=accomodation")

?

Link to comment
Share on other sites

I'm confused as to why you need *= . 

This should just work fine

$pages->get("/places")->children("tags=foodID, tags!=accomodationID")

Of course you're right. This was just a leftover from when I was working with the page names instead of IDs.

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...