Violet

[SOLVED] What fundamental error am I making in my $pages->find selectors when using the != operator?

Recommended Posts

I'm having trouble with my selectors when using !=. I'm sure I'm making some newbie mistake, but I'm just not sure how to fix it. 

This code below functions as expected:

$results = $pages->find("template=basic-post, limit=1, path=$post1path, sort=-userpubdate");

but this one (the one I actually need) doesn't work:

$results = $pages->find("template=basic-post, limit=1, path!=$post1path, sort=-userpubdate");

It results in an internal server error. How should I have phrased it instead? My intent is to find all pages with the basic-post template but excluding that one specific post.

In both cases, 

 $post1path = $post1->url;
 echo $post1path;

where $post1path echoes as expected with the path of post1. The variables therefore seem to be working, but I must be making some sort of fundamental newbie error in my page selection. 

I would appreciate any guidance that anyone can give. I didn't want to use slice() or other things after getting the page array, as I want to be able to use pagination.

 

UPDATE: :blush: I *think* I have gotten around the issue by using ID's instead, where $post1id = $post1->id.

$results = $pages->find("template=basic-post, limit=1, id!=$post1id, sort=-userpubdate");

And it seems to paginate correctly as far as I can see - I still have to do more testing with a bigger array to be certain, but it's working on my small test array for now. I'm still curious why path!=$post1path did not work, if anyone would like to comment on that for me. But at least there is a solution that, so far at least, seems to work.

  • Like 1

Share this post


Link to post
Share on other sites
2 hours ago, Violet said:

It results in an internal server error.

Not sure why you are seeing that. What you should see is an exception message that explains things pretty well:

Quote

Exception: Operator '!=' is not supported for path or url unless: 1) non-multi-language; 2) you install the PagePaths module.

IDs are the way to go for that sort of selector, so I would stick to what you have changed to rather than install PagePaths.

Edit: it just occurred to me that you may not be seeing the exception if do not have debug mode enabled. In /site/config.php:

$config->debug = true;

You should enable debug mode while you are developing a site and then disable debug mode when the site goes to production.

  • Like 3

Share this post


Link to post
Share on other sites

Thank you so much @Robin S for clearing up that mystery! I had not realized that != was not supported by default for path or URL. I appreciate this info.

And yes you are 100% right, I had debug mode off:excl:; I probably should at least turned it on temporarily while trying to figure out my problem. I'd completely forgotten about it. I'm developing my site live instead of starting on a local server, so for security reasons I had turned off debug mode. That said, I should have turned it back on while I was trying to figure things out with my selectors. Will definitely remember to do that first when I next get stuck, as I can see from what you're saying that the debug exception messages will give me valuable clues about what I'm doing wrong.

Thanks again, I really appreciate your help. Marking this thread as solved.

Share this post


Link to post
Share on other sites
1 hour ago, Violet said:

so for security reasons I had turned off debug mode

Tracy will report all those errors even with debug mode off - just use the "Force superuser into development mode" option so that it shows on a live production site when you are logged in.

  • Like 4

Share this post


Link to post
Share on other sites
On 14/10/2017 at 5:24 AM, Robin S said:
  Quote

Exception: Operator '!=' is not supported for path or url unless: 1) non-multi-language; 2) you install the PagePaths module.

That's handy, thanks. Used it for ID but wouldn't have known this.

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By hellomoto
      I have
      $select = 'template=post, when<=now, sort=when, '; $results = $pages->find($select); then output the results' data. It works fine without the sort=when. With it, I get this:
      Error: Exception: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias: '_sort_when' (in /Applications/AMPPS/www/website/wire/core/PageFinder.php line 384) what is this
      I have this elsewhere
      $start = date('Y', $pages->get($select.' sort=when')->getUnformatted('when')); and it works fine, returns the earliest year.
    • By Alex CA
      In my search.php template, I am using 
      $selector = "title|body%=$search_term, limit=50"; to find the top 50 search results for the page.
      I implemented this following this link https://processwire.com/api/selectors/
      My question is how does the selector sort its results? Does it look at the number of time the $search_term has occurred in the page or does it start searching from the root page to all the children.
      Also, will this change if I do not put any limits to the search results?
       
    • By abdus
      I have a template my-template that has a page reference field myUser. The field is set to a user with custom template (using $config->advanced). When I try to filter pages with my-template whose myUser.name or myUser.title includes a certain keyword, I get inconsistent results. Here's what I mean:
      // works because tom is an exact match $pages->find("template=my-template, myUser.name=tom"); // doesnt work even though myUser name is 'tom' $pages->find("template=my-template, myUser.name*=tom"); // doesnt work despite myUser's title being 'Your Mom' $pages->find("template=my-template, myUser.title*=tom"); // doesnt work $pages->find("template=my-template, myUser.title|myUser.name*=tom"); // doesnt work at all $pages->find("template=my-template, createdUser.name*=tom"); // works $pages->find("template=my-template, anotherPageField.title*=value"); // works $pages->find("template=my-template, anotherPageField.title|anotherPageField.body*=value");  
    • By OLSA
      Hello for all,
      sorry for this topic title but let me try to explain.
      Website has product items, where sometimes products go to "Outlet" (actions/discounts).
      Main part here is that in "action" status:
      a) product can have new price and go alone to discount
      OR
      b) product is in group with other products ("collection", and new price is only valid in case when customer buy full collection).

      First problem was how to get this :
      Product items:
      A on action
      B on action in group with "D"
      C  on action
      D on action in group with "B"
      ---------------------------------------------------
      Outlet list page need to show 3 items:
      1. item (A)
      2. item (B, D) (eg. item image is "TV+sofa")
      3. item (C)
      First what I done, was that I created Outlet "category" with children, where children page has fields: title, group image and page select field (to select products from another page tree). But that was wrong and dirty (few foreach, pagination..., etc. that was bad concept).
      Than I decided to place page select field on product item, and from product item select it's group (single select field). And that was ok, and I like it also because administration in any variant need to go to product to set new price. Right now, administration first create group page with some title and with some image. After that, go to product item, check field "action", write new price, and - if - product is part of group - add - it to group.

      There is part of code on "Outlet" list page:
      // outlet-list.php // $items: single items // outlet: page field, it's parent is "Outlet" list page $items = $pages->find('template=product-item, action=1, outlet.count=0'); // outlet=0 or outlet=''... $group_items = $pages->find('template=product-item, action=1, outlet.count>0'); // group items ("merge") foreach( $page->children() as $group ){ // go through Outlet children ("group id pages") if($group_items->has("outlet=$group->id")){ // if in array are items with that group id $group->singles = $group_items->find("outlet=$group->id"); // append to page "group" new attribute and fill it $items->add($group); // now go back and append to "items" new type of "item" } } // pagination $pagination = $items->renderPager(); After it in rendering process I get basic product items, and "group" items together inside list page.
      Here is the problem:
      When I go and set some of Group page as "unpublished", I expect, after it, to get that group subitems shows as alone (singles) inside Outlet. But not.
      They doesn't shows!?
      In that case outlet.count return null, but real "singles" return false. I try more options with selector (and different page select field types) but can't get what expect to be. 
      // selector to return singles 'template=product-item, action=1, outlet.count=0' // tried options outlet=0, outlet='', outlet=0|"", outlet.count<1 etc... Sorry for this long, long topic. If someone has some idea what and where... I would be grateful
      Best regards! 
      p.s. if all this is confused, last sleeping was... can't remember
    • By verdeandrea
      Hello!
      I have pages that have separated fields for first name and last name.
      I'm working on a search form that has one single input field, so that if someone search for "John Doe" it should find all pages that have "first_name = John" and "last_name=Doe" or, of course, "first_name=Doe" and "last_name=John".
      What would be the best use of selectors and operators in this case?
      I came up with
      first_name=John|Doe, last_name=John|Doe so that i should split the search key with |
      I'm not sure this is the best solution.
      What would you suggest?
      Thank you!