Jump to content

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


Recommended Posts

Posted

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
  • Violet changed the title to What fundamental error am I making in my $pages->find selectors when using the != operator?
Posted
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
Posted

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.

  • Violet changed the title to [SOLVED] What fundamental error am I making in my $pages->find selectors when using the != operator?
Posted
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
Posted
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.

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
×
×
  • Create New...