Jump to content
alevine

Confused with Selector queries

Recommended Posts

I feel like I'm getting super lost with all of my questions today :)

I have a Checkbox field, "premium".

This field is added to a template, myContent

I have 2 pages created with the myContent template.  One has premium checked, the other does not.

My query is:  Show me all Pages using 'myContent' as a template, and whose premium field is not selected (0):

 selector:   template=myContent,premium=0

This query is returning 2 Pages, which is should not.  When I iterate through the returned list, I can see ->premium as set 1 for one, 0 for the other.

If I change "premium" in the selector to some random value that doesn't exist as a field name, the query runs and still returns 2 Pages.

 selector:   template=myContent,feujfhejhejejhejhefje=0

I would think it should error out, but instead seems to be doing a short-circuit evaluation.  Are comma-delimited selectors not "AND"ed together?

If I place the premium field at the start, or even by itself

 selector:   premium=0

I get this error:

Notice: Uninitialized string offset: 0 in C:\dev\xampp\htdocs\pwire\wire\core\Selector.php on line 49

Fatal error: Exception: Field does not exist: (in C:\dev\xampp\htdocs\pwire\wire\core\PageFinder.php line 248)

#0 [internal function]: PageFinder->___getQuery(Object(Selectors))
#1 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(271): call_user_func_array(Array, Array)
#2 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(229): Wire->runHooks('getQuery', Array)
#3 C:\dev\xampp\htdocs\pwire\wire\core\PageFinder.php(145): Wire->__call('getQuery', Array)
#4 C:\dev\xampp\htdocs\pwire\wire\core\PageFinder.php(145): PageFinder->getQuery(Object(Selectors))
#5 C:\dev\xampp\htdocs\pwire\wire\core\Pages.php(144): PageFinder->find(Object(Selectors), Array)
#6 [internal function]: Pages->___find('=0')
#7 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(271): call_user_func_array(Array, Array)
#8 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(229): Wire->runHooks('find', Array)
#9 C:\dev\xampp\htdocs\pwire\site\assets\cache\HannaCode\pages_query.php(3): Wire->__call('find', Array)
#10 C:\dev\xampp\htdocs\pwire\site\assets\cache\HannaCode\pages_que in C:\dev\xampp\htdocs\pwire\index.php on line 214

Please point out what I'm doing wrong!

Thank you.  Again! :)

Share this post


Link to post
Share on other sites

The Fatal Errors suggests you do not have a field by that name. Have you checked typos? Do you really have a field called premium? Otherwise your selector should work. Also post your query code here if you've doubled-checked field name is correct...Uninitialised string offset error can also occur if you are treating a string as an array...

Share this post


Link to post
Share on other sites

The Fatal Errors suggests you do not have a field by that name. Have you checked typos? Do you really have a field called premium? Otherwise your selector should work. Also post your query code here if you've doubled-checked field name is correct...Uninitialised string offset error can also occur if you are treating a string as an array...

As I showed in some of the examples, I can retrieve values from ->premium when the Pages are returned.  As well, the query doesn't error if I give it nonsense for a field name as a 2nd+ selector value.

Query code (as Hanna code entry):

$foundPages = $pages->find($pagesQuery);

echo serialize($foundPages);

Field:  query_pages, Type: Concat

value:  [[pages_query pagesQuery=template=myContent,premium=0]]

The above value returns 2 pages, when it should only return one.  If I look at ->premium on those 2 returns, one is 1, one is 0.

I've tried putting the value for pagesQuery in single (') and double (") quotes; with either form of quotes, I get:

Notice: Uninitialized string offset: 0 in C:\dev\xampp\htdocs\pwire\wire\core\Selector.php on line 49

Fatal error: Exception: Field does not exist: (in C:\dev\xampp\htdocs\pwire\wire\core\PageFinder.php line 248)

#0 [internal function]: PageFinder->___getQuery(Object(Selectors))

#1 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(271): call_user_func_array(Array, Array)

#2 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(229): Wire->runHooks('getQuery', Array)

#3 C:\dev\xampp\htdocs\pwire\wire\core\PageFinder.php(145): Wire->__call('getQuery', Array)

#4 C:\dev\xampp\htdocs\pwire\wire\core\PageFinder.php(145): PageFinder->getQuery(Object(Selectors))

#5 C:\dev\xampp\htdocs\pwire\wire\core\Pages.php(144): PageFinder->find(Object(Selectors), Array)

#6 [internal function]: Pages->___find('template=myCon...')

#7 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(271): call_user_func_array(Array, Array)

#8 C:\dev\xampp\htdocs\pwire\wire\core\Wire.php(229): Wire->runHooks('find', Array)

#9 C:\dev\xampp\htdocs\pwire\site\assets\cache\HannaCode\pages_query.php(3): Wire->__call('find', Array)

#10 C:\dev\xampp\htdocs\pwire\site\assets\cache\Han in C:\dev\xampp\htdocs\pwire\index.php on line 214

Share this post


Link to post
Share on other sites

Okay, here's something.

If I move the query to my page, it's picking up the additional parameter to the query

$myPics = $pages->find("template=myContent,premium=0");

So, this tells me somewhere in the translation between defining the Hanna code, the field declaration, and invocation, only the first parameter (template=...) is being picked up, and everything after is being stripped. 

The Hanna code is only receiving "template=myContent"

If I change the field value to be sent in quotes:

[[pages_query pagesQuery=template=myContent,premium=0]]

Hanna is getting: :  template=myContent,=0

Im sure it has something to do with using the Concat fieldtype doing value substitution.

Thoughts on what I need to do to amend that?

EDIT:  The selectors are fine.  I just need to modify the Concat module to not do value substitution and all is well.  Once I get my selector properly escaped, that is for including a $page reference in the query.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By jds43
      Hello, I have a Page Reference by template radio button field to promote a certain page (only two options), but I'd like to target the page that isn't selected. This would be used dynamically throughout the site.
      Does anyone know how I could accomplish this? Would I use something like remove() or not()?
       
    • By Hubris
      Hi there!
      I'm using some page reference fields to create lists of tags, categories, years, etc.. I'm able to find the pages like so:
      $pages->find("template=project, {$filter}={$page->title}"); Which dynamically does something like: 
      $pages->find("template=project, tags=Experimental"); Only if the value (the page name, like "Experimental") starts with letters. If it starts with numbers, find returns nothing.
      Why is this and how can I fix it?
    • By Elchin
      Hi.
      I want select pages where now between date and end_date or now bigger than date and end_date is empty.
      I have five tried variants:
      $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("foo=(date<$start,date_end=''),bar=(date<$start,date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date<$start,(date_end='',date_end>=$start),sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end=''|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("!date_end|date_end>=$start,date<$start,sort=-date,limit=12"); $start = strtotime(date('Y-m-d') . " 00:00:00"); $results = $page->children("date_end>=$start|!date_end,date<$start,sort=-date,limit=12"); All this variants not worked for me and returned zero results.
    • By pwFoo
      I played with the Selectors object and would like to use it for a special use case...
      That is a custom Selectors object with dummy data converted to an php array to see the structure (Selectors object is a WireArray with "fields" added)
      Array ( [0] => Array ( [0] => Array ( [field] => seg1 [value] => val1 [not] => [group] => [quote] => [forceMatch] => ) [1] => Array ( [field] => seg2 [value] => val2 [not] => [group] => [quote] => [forceMatch] => ) ) )  
      But instead of "seg1" the field name is "field" with value "seg1" (= my field name).
       
      So I can't search the Selectors WireArray (= custom WireArray with added Selectors objects) with PW "find('seg1=val1')", Is there a way to search with "find()" or build a simple wrapper to make the elements searchable / filterable with find()?
    • By celfred
      Hello,
      I'm facing a weird behavior (to me)... Why are these requests not returning the same values ?

        // Test 01 : not working > returns empty $allPlayers = $pages->find("team=$team"); // Returns the 10 players (1 of them has HP=14, others have HP>15, no players have coma=1) $dangerPlayers = $allPlayers->find("(HP<=15), (coma=1)")->sort("coma, HP"); // Returns nothing ??? // Test 02 : Working as expected $dangerPlayers = $pages->find("parent.name=players, team=$team, (HP<=15), (coma=1)")->sort("coma, HP"); // Returns the low HP player
      If you can explain this to me, I would appreciate because this is causing me a headache right now 🙂 
      Thanks !
×
×
  • Create New...