Jump to content

Selector by field page


diegonella
 Share

Recommended Posts

Hello everyone
I want to filter all children adicional_hab field (product type) is NULL or empty or has X page
 
What I want is to filter all the pages that adicional_hab field is empty or has selected a value.
 
To translate it into SQL
SELECT * FROM adicional WHERE adicional_hab IS NULL OR adicional_hab = 'standard'
 
 
I tried
$adiconal->children("adicional_hab=standard|''");
 

On the other hand there ay any way to make a print and view the sql query that is running with filters that these apply?

Thank you very much, best regards

Diego

 
 
Link to comment
Share on other sites

Hi Diego,

Going by the title of your post, I am assuming that "standard" is the name or title of a page that would be selected via a Page Field? PW does not store the name or title of the page referenced in a Page Field. It goes one better; it stores the ID of the selected page. So, you will have to reference the ID of standard instead of using "standard". E.g. the ID could be 1035. Use that instead. Is this a single Page Field, btw? By storing the ID, PW enables you to easily get all the information about the referenced page. 

This is just to get you started on restructing your selector (not meant to work immediately). I have to go but may revisit this post if you are still stuck and haven't received help yet... :)

Link to comment
Share on other sites

Adrian,

I need to filter the pages in which the "Field Page" is null or with ID xxxx

I am not sure you can do this in the same condition, i.e. I am not sure you can do...

field_page=1234|' ' or even field_page=1234|0. I tried but got MySQL errors. I also tried getting the name of the referenced page first and using that as a condition, i.e. field_page=standard|' ' but no joy. Maybe there is a way of doing this, I don't know. Only tested quickly. Testing for AND is easy but not OR in this case.There will be other pointers, am sure :)

Link to comment
Share on other sites

When searching for empty fields, you can do this:

$something = $pages->find('myfield=')l

So literally put nothing after the =. In your case though this might work:

$adiconal->children('adicional_hab=standard|'); // I just went for single quotes for legibility

Not sure leaving a blank after the pipe | - signifying OR - will work, but give it a shot.

Link to comment
Share on other sites

field_page=0 will return also all the pages that don't even have this field i their template. The correct way to return pages with an empty page field is field_page.count=0. Unfortunately there is no way of combining field_page.count=0 and field_page=123 in one selector, so you would have to create two different arrays, and merge them. You can do this with $a->import

$myPages = $pages->find("field_page.count=0")->import($pages->find("field_page=123"));

After this you will have an array with all the desired results and you can even sort it as you would in a selector:

$myPages->sort("created");

Edit: Pete, i just saw your answer. I don't think that it works for page fields...

  • Like 2
Link to comment
Share on other sites

@Pete,

Diego wants to match two conditions - where the field is empty or where the same field has the id=123. I've tried with leaving it empty as you suggest (i..e, nothing after =) + specifying an ID but it doesn't work :). Diego used "standard" before, trying to match the name of the page referenced in the Page Field but we know PW does not store the name/title but the ID...Anyway, one gets the following error

Fatal error: Exception: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias

if you try  the selector (page_field=1234|) or other variants as I show in my examples above

Link to comment
Share on other sites

@Pete,

Diego wants to match two conditions - where the field is empty or where the same field has the id=123. I've tried with leaving it empty as you suggest (i..e, nothing after =) + specifying an ID but it doesn't work :). Diego used "standard" before, trying to match the name of the page referenced in the Page Field but we know PW does not store the name/title but the ID...Anyway, one gets the following error

Fatal error: Exception: SQLSTATE[42000]: Syntax error or access violation: 1066 Not unique table/alias

if you try  the selector (page_field=1234|) or other variants as I show in my examples above

Yes, I'm using 2.3 PW

Link to comment
Share on other sites

Diego, try Diogo's code above. It works like a charm. Like I said, there are some very clever people in the forums. He's one of them ;). You could make it more specific by using template or parent, etc in the selector or using a "get", like so:

$x = $pages->get(2064)->children("single_page_field.count=0")->import($pages->get(2064)->children("single_page_field=1234"));
  • Like 2
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

×
×
  • Create New...