Jump to content

Recommended Posts

Posted

I noticed something strange, with a selector I cannot explain why this happens.

$item_number = ' ';
$p = wire('pages')->get('template=product, item_number=' . $item_number);
echo $p->title;

The code above finds a page with an item_number set to the value of "50032". There is no space (had a look at the DB).

I would have though using the = operator the code above gets nothing or if present something with an empty item_number. But no with a totally different value.

It works as expected if I change the code to:

$p = wire('pages')->get("template=product, item_number='{$item_number}'");

Does anybody know why the first code example works differently?

image.thumb.png.4c0f489c79894757d7b611cf291264be.png

PW 3.0.243

Posted

Might there be something in the trash with that number? get() skips any access control check!

Posted

No, it's deftly that particular page, just sitting in the page tree like many others. It is, by the way, the first page in the page tree with an item_number (the pages above have empty item_number values). 

  • Like 1
Posted

Both codes are NOT giving the same selector, you could check by printing it.

First case gives: "item_number= " (with a space)
Second one gives: "item_number=' '" (space inside quotes)

To find empty values, you can just use "item_number=''" (no space inside quotes), or "item_number=" (nothing after equal).

But I don't know why the first one is returning a page with item_number=50032. If you're sure everything is right on your side, maybe report a bug on Github.

Posted

Thanks for your answer. To clarify, I don't want to get pages with empty values, nor do I have a problem with finding what I need. I'm curious why a blank search query produces non-blank results. I might post this question on GitHub later.

  • Like 2

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