Jump to content

Search the Community

Showing results for tags 'selector'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to ProcessWire
    • News & Announcements
    • Showcase
    • Wishlist & Roadmap
  • Community Support
    • Getting Started
    • Tutorials
    • FAQs
    • General Support
    • API & Templates
    • Modules/Plugins
    • Themes and Profiles
    • Multi-Language Support
    • Security
    • Jobs
  • Off Topic
    • Pub
    • Dev Talk

Product Groups

  • Form Builder
  • ProFields
  • ProCache
  • ProMailer
  • Login Register Pro
  • ProDrafts
  • ListerPro
  • ProDevTools
  • Likes
  • Custom Development

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

  1. I am trying to filter my $pages with a find($selector method). $matches = $pages->find($selector); and this is an example of what my selector looks like $selector = "include=all, title|body~=$q, limit=50"; In this case, it only searches according to the matching exact words. For example:we search="art", the result="art times","these art",.... Is there any way to search based on the alphabet? For example: we search="ab", the result="absolutely correct","abstract art",....
  2. I understand from the selectors documentation: I have a repeater field `promo_codes` consisting of text field `title` and an integer field `number1`. I'm running a find: $page->promo_codes->find('title=gmtest'); The database column collation is `utf8_general_ci` so I would expect this to work, but it only works when I match the case exactly ("GMTEST"). This is on PW 3.0.42. Any ideas? Is there an exception for finds on repeater fields?
  3. Hi all, today I've run into some strange error when using selectors. The following selector works fine: $pages->find('template=TemplateName, (many|of|different|fields*=Searching), (year=Searching), (year>=1941, year<=1960), author*=unknown, publisher*="two, maybe three words"|unknown|"another two, maybe three words", area*=All'); Whereas this one throws an error: $pages->find('template=TemplateName, (many|of|different|fields*=Searching), (year=Searching), (year>=1941, year<=1960), author*=unknown, publisher*="two, maybe three words"|unknown, area*=All'); The only difference is in publisher field having only two values. The error is Exception: Unknown Selector operator: '' -- was your selector value properly escaped? Additional info: ProcessWire 3.0.62 All values are sanitized using $sanitizer->selectorValue(string) publisher value usually has commas or parenthesis publisher="one, two"|"three, four" works publisher="one, two"|three|"four, five" works publisher="one, two"|five doesn't work publisher=five works The only conclusion I can make is the selector fails when the last value of publisher is a single word. Any thoughts? All help is greatly appreciated! Jan
  4. I have the following page structure Continents Countries Regions I then have pages "walks" which has a multi-select Page Reference field Regions (I've tried using dynamic fields for this but it wasn't accomplishing what I needed) which has the regions listed by country and then the region (continent is more for searching later on so doesn't need to be seen here). I'm trying to get a count of firstly all the walks within a continent, then country, then region but can't seem to figure out the selector for this. Thanks, Heather
  5. Hello, I passed through a lot of documentation about selectors and a few post in the forum but and I did not find my answer so I'll try here :). Question: Is there a way to find pages that have a certain field attached to his template ? Use case: // Site structure Products Computers Computer #1 (has field cached_details) Computer #2 (has field cached_details) Electronics Test #1 Pet Supplies Test #2 (has field cached_details but is empty) // If I want to get all children of page "products" that contains the field "cached_details" I would do something like this // $products => PageArray $results = $products->children("has_field=cached_details"); // or this $results = $products->children("cached_details!=null"); // Expected: $results would contains [Computer #1, Computer #2, Test #2] // Instead I have to do this $results = new PageArray(); foreach($products->children as $child) { if ($child->hasField("cached_details") === true) { $results->add($child); } } Thank you in advance guys :),
  6. Hi all, From my attempts it seems like this is not possible but thought I would raise it here before scrapping the idea and trying something else. I have an importer script reading a third party feed and creating some pages (page_type_A) based on that. It also creates some other pages (page_type_B) which are by default set to unpublished as the third party don't seem to have control over some of the data they send us, so we set them to unpublished so that someone on our end needs to approve them, so far so good. The issue I have encountered is that page_type_A at creation uses the API to set one of its fields to a particular page_type_B, the field is setup as PageSelector. When I look at the database this seems to work fine, but if you go into page_type_A the Page Selector list is always preset to blank? I updated the Page Selector and set the Selector String to use "include=all" which does populate the drop down with all the correct pages but since there all unpublished it never seems to be preselected to the one which is actually saved as in the DB. Hope that makes some sort of sense.
  7. 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?
  8. I'm trying to figure out how to create a selector that will find pages where a certain text field is either empty of unique. I have about 3500 records where the majority of have a specific field which is simply empty, there some records however that will have a certain value filled in this same field and some of these values are the same. I want to only select the first page which is found with this value and exclude the rest of these pages with the same value. Any ideas?
  9. Hi guys, I'd really appreciate some help from you. I am wondering how I would about using the Selector field type within a repeater. It seems kinda bad design to have multiple selectors (e.g. Grid 1, Grid 2, Grid 3) when I could use a repeater for it. Using Ryan's example, I have managed to get my repeater to work foreach($page->grid_repeater as $grids) { echo "<h2>{$grids->grid_type}</h2><p>"; echo " }
  10. Hi all, Im looking for a selector that gets the pages added a specific time frame (eg. from yesterday 9:00pm to today 9:00pm). Is there a existing selector im missing or does someone now a good solution for this? Thanks in advance .
  11. Found myself needing to filter repeater items based upon start and end date fields. These fields aren't required, so repeater items with no dates should be included and those with dates (or a just one date -- start or end) should be evaluated for inclusion. I slowly figured out that I was dealing with in-memory filtering (of a RepeaterPageArray) and not a database-driven operation. So, that eliminated the possibility of using or-groups in my selector. I still thought I could use the 'filter' and 'not' functions to get the job done. Turns out the way selectors are handled for in-memory filtering is quite different from database-driven selectors. Here is what I want(ed) to do to filter the dates: // Start date not specified or in the past $repeater->filter('start_time<='.$now); // Not when end date is specified and has passed $repeater->not('end_time>0, end_time<'.$now); The first one worked exactly as expected. The second it where I ran into problems. The 'filter' function (which calls the 'filterData' function) takes a $selector argument. From everything I read about selectors, I assumed that the entire selector would have to match. In other words, each comma represented an 'and' scenario. Turns out that each separate comma-separated-selector in the $selector as a whole gets evaluated independently. In the case of the 'filterData' function, the elements are removed if any one of those selectors matches. Essentially, we have an 'or' scenario instead of an 'and' scenario. In my case above, there was no way for me to filter for a non-empty date AND one that occurs before a given date...at least that I could think of. So, my main question is if the filter (and related) function should operate on the entire selector passed to the function instead of its individual parts in some sequence. That is what I would have assumed a selector to do. In my project, altering the segment of the WireArray::filterData function solved my problem for now. ...at least till I forget about it and overwrite it when I upgrade next. Here is the code I changed within the function // now filter the data according to the selectors that remain foreach($this->data as $key => $item) { $filter_item = true; foreach($selectors as $selector) { if(is_array($selector->field)) { $value = array(); foreach($selector->field as $field) $value[] = (string) $this->getItemPropertyValue($item, $field); } else { $value = (string) $this->getItemPropertyValue($item, $selector->field); } if($not === $selector->matches($value)) continue; $filter_item = false; break; } if($filter_item && isset($this->data[$key])) { $this->trackRemove($this->data[$key], $key); unset($this->data[$key]); } } I would love to hear what you all think. If I have misunderstood something, then I would welcome a different solution. Thanks!
  12. <b>Fatal error</b>: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? field='id', value='!=9022', selector: 'template=city,sort=random,start=0,id!=9022,id!=9011,id!=9028,id!=1099,limit=8' (in /opt/bitnami/apps/processwire/htdocs/wire/core/Selectors.php line 357) I'm getting this confusing error with a selector, it seems to be implying that id isn't a field which is obviously not right. Any idea what might cause this bug?
  13. Hello, I'm trying to build a selector array to work with an OR operator. I need all pages where the datetime field ("date_pub_end") is empty or in the future. In a selector string this could be solved with the following two examples (with and without OR-group) $selector1 = "... ,!date_pub_end<={$now}, ..."; $selector2 = "... ,(date_pub_end=''),(date_pub_end>={$now}), ..."; But I'd like it to work in selector arrays, so far I couldn't find a solution.
  14. I use pagination modul. I have a field which has born year info. But I put the years with sign "-" for BC (Before Christ). my selector sorts like as text. -384, -4, -412 .. it must be: -412, -384, -4 selector: $pages=$page->children("limit=60, sort=date_field"); I want to order my pages like as php natsort function. thank you.
  15. Hi all, Currently I am working on a filter for all the products in a category. So I've set up a class and built a (PW) form in it. When the user clicks on continue the form should return a processform function which sets the variable of the form in a session. Later in the file I want to read out that session and use that variable to select which products should show up and which should be hidden. So now with code examples to make it a bit more clear for you: In my file I start with a class: class classname { public function ShowForm() { $form = $this->Form1(); if ($this->input->post->submit) { if ($this->processForm1($form)) $this->session->redirect("./"); } return $form->render(); } Then a form inside the class: protected function Form1() { $form = wire('modules')->get("InputfieldForm"); $form->description = "Fill in the fields to find the mouse which fits your wishes"; $form->label = "Mouse Selector"; $form->action = "./"; $form->method = 'post'; $f = wire('modules')->get("InputfieldRadios"); $f->name = "Hand"; $f->label = "label"; $f->addOption(1, "1"); $f->addOption(2, "2"); $form->add($f); $this->addSubmit($form, 'Continue'); return $form; } This function is called when the user submits: protected function ProcessForm1($form) { $form->processInput($this->input->post); $this->session->hand = (int)$form->get("Hand")->value; } As you see I store the variable of the submitted form in a session. After closing the class I continue with building the page and then I want to read out that variable: $value = $this->session->hand; $content .= "Value of 'Hand': " . $value; But when I execute this on my website I cannot see the value of the form. Have I done something wrong or how can I fix this? Thanks in advance, ~Harmen
  16. Hi ! I'd like to know if there is a way to "select" the max value among selected fields. I have to select the higher hour field of a group of pages (with the same template) and display it on another field (page type) in a backend page. Could be "max(hours)" with mysql. I hope I'm clear Thank you guyz !
  17. I am using the below to go several levels deep, but when using a select of "limit" or "sort" I am getting strange results. For example, if limit=2 I get five results. If limit=3 I get six results. I am sure I have messed up something. Maybe there is a better way? $cats = $pages->get("/mypage/")->children; // get children of the parent foreach ($cats as $cat) { $menu .= "<div>"; $menu .= "<h2 class='titlebg'>$cat->title</h2>"; if($cat->children) { // if they have children $menu .= "<ul>"; foreach($cat->children as $subchild) { foreach ($subchild->children("limit=2, sort=-date, sort=title") as $child) { $menu .= "<li><a href='{$child->url}'>$child->title</a></li>"; } } $menu .= "</ul>"; } $menu .= "<span><a href='{$cat->url}'>See More</a></span>"; $menu .= "</div>";
  18. Hi everybody, I am working on a project where I have a search form with an input field, that should search over a lot of PW fields (text and pagefields). What I am trying to get is something like this: $pages->find("title|body|sidebar|summary|intro|keywords|country.title%='word1 word2 word3'"); The problem is now the search input. If I insert two words (word1 word2) it should look into every field, just like: $pages->find("title|body|sidebar|summary|intro|keywords|country.title%=word1, title|body|sidebar|summary|intro|keywords|country.title%=word2"); So far so good. but there is the possibility to add up a lot of words, and then MySQL is at its join limit and quits with an error. Is there a possibility to prevent this? I even limit the words for the input but this is not good. On the more complex site I tried the fieldtype "cache". So far so good, but now there is the problem with pagefields that are searched too like "country.title". This is not working, as I read in the forum, and in the database there is only the ID of the pagefield in question. On a normal search by selector I would definitely use that, but here it is not the point, because the input is a word, not an ID. Example: $pages->find("cached_fields_in_fieldtype_cache|country.title%=word1, cached_fields_in_fieldtype_cache|country.title%=word2"); I know the second example is not the best for this kind of search. It is easy to put an OR selector with the values together, but an AND selector (third example) is limited to the MySQL functionality. I want to is a search ability like some might know from Joomla (no I am not a Joomla fan or developer, but the client is ). In Joomla there are the three possibilities to search from an input text: any word (same as selector operator "~=" ?) all words (same as selector operator "*=" or "%=" ?) exact wording (same as selector operator "*=" ?) There is no limitation of words in the search input, so I am wondering how this is working. So, what I got at the end are two options for the selector: 1: $pages->find("cached_fields_in_fieldtype_cache|country.title*='wor d1 wo rd2 word3'"); // mostly no results at all if word is only part of the complete word. Word length limitation to at least 4 characters The first option here is only working if the word is complete. If the search is "wor" and not "word1" then I get only result on one word input, but do I add another word to it, it gets no result. 2: $pages->find("cached_fields_in_fieldtype_cache|country.title%=word1, cached_fields_in_fieldtype_cache|country.title%=word2, cached_fields_in_fieldtype_cache|country.title%=word3, ..."); // result limited by word count Now I am almost on the model to remodel the search and limit it only to some parameters (as it should be...), but this would question the the clients "wish" for the search. Another point is to extend the selector with more pagefields ("cached_fields_in_fieldtype_cache|country.title|method.title|town.title" etc.) that can not be put into the cache fieldtype. So the MySQL limit is coming back again... is it even possible to store the subfield of a pagefield in the cache field? Does anyone know how it would be possible to get that kind of search running? Maybe a direct MySQL search? filter results by adding part or complete words (to find the one and only result) search with multiple words (no MySQL error because of join limitation -> I am already cutting off too many words) Thanks for your help!
  19. Hi, Our ProcessWire website has a simple site search, which is implemented following the ProcessWire search demo code. It uses the %= operator to get broader results. $queryResults = $this->pages->find('title%=应用'); // return everything The problem: It will return ALL pages. The reason is probably that %= uses SQL LIKE and SQL needs to be told that the search string contains unicode characters by adding 'N' as the prefix. At least this is what I think I learned from: http://stackoverflow.com/questions/22156413/how-to-select-rows-with-chinese-japanese-characters I tried this, but I still get everything: $queryResults = $this->pages->find("title%=N'应用'"); // return everything I also tried encoding my chinese text: $queryResults = $this->pages->find('title%=\u5e94\u7528'); // no results But now I get zero results. And by the way: The ~= operator also returns zero results: $queryResults = $this->pages->find('title~=\u5e94\u7528'); // no results $queryResults = $this->pages->find('title~=应用'); // also no results I guess I could build my own SQL queries, but we have already build a very nice customized search based on ProcessWire selectors and would really like to stick with them. Any idea how to solve this? Many thanks, René
  20. Hello, I'm having a little question with this part of code : $rank = $pages->get("template=team, name=$selectedTeam")->rank->name; if ( $rank == '4emes' || $rank == '3emes' ) { $allPlayers = $pages->find("template=player, team.name=$selectedTeam"); $allConcerned = new pageArray(); $notConcerned = new pageArray(); foreach($allPlayers as $p) { // Find players having at least 3 free elements if ($p->places->count()+$p->people->count() >= 3) { $allConcerned->add($p); } else { $notConcerned->add($p); } } $notConcerned = $notConcerned->implode(', ', '{title}'); /* $allConcerned = $pages->find("template=player, team.name=$selectedTeam, (people.count+places.count>=3)"); // Find players having at least 3 places OR 3 people */ /* $notConcerned = $pages->find("template=player, team.name=$selectedTeam, (places.count+people.count<3)")->implode(', ', '{title}'); */ It works fine the way it is, but I just want to make sure that the commented part is not possible with PW (yet?) : having a selector such as people.count+places.count>=3. I feel like it would be more concise and more readbable/maintainable (2 lines instead of 11). Thanks in advance for your insight and advice
  21. Hello, I've been working on building a find query and I think I need to be able to do an OR search on multiple selectors, all of which have a number of possible values. The first way I did this was with three queries: // Categories if($page->Categories->count > 0) { foreach($page->get("Categories") as $category) { $category_array[] = $category->name; } $category_string = implode("|", $category_array); $same_categories = $pages->find("template={$page_type}, Categories={$category_string}")->filter("id!={$page->id}"); } // Tags if($page->Tags->count > 0) { foreach($page->get("Tags") as $tag) { $tag_array[] = $tag->name; } $tag_string = implode("|", $tag_array); $same_tags = $pages->find("template={$page_type}, Tags={$tag_string}")->filter("id!={$page->id}"); } // ConnectedClient if(in_array('ConnectedClient', $page->fields)) { $same_client = $pages->find("template={$page_type}, ConnectedClient={$page->ConnectedClient}")->filter("id!={$page->id}"); } if($same_categories->count > 0) $matches->import($same_categories); if($same_tags->count > 0) $matches->import($same_tags); if($same_client->count > 0) $matches->import($same_client); But for some reason, only the first "$matches" seems to stick. So to me, it would make sense to be able to structure a find query like this: $search = $pages->find(" template=post|project, [Categories=one|two|three]|[Tags=yes|no|maybe]|[ConnectedClient=1065] ")->filter("id!={$page->id}"); Does this make sense? I need to find all pages that match [Tags=yes OR no OR maybe] OR [Categories= one OR two OR three] OR [ConnectedClient=1065]. I realize it might turn into a SQL-needed scenario, but given the flexibility of Processwire, the ability to string together a query like this would be super nice. Is there a way?
  22. Hi, I'm sorry if this has been adressed before but I couldn't find anything about it. I'm pretty new to processwire but not to php or object developpment. I'm working on a blog and the request was to add a custom date field on articles that allows the user to override the "date" associated to the article. It's basically a publish date. If set, that date is used to sort the article and also if the date is in the future the article will not be displayed on the website. Here is the selector I used to sort my articles list before: $pages->find('template=news, sort=-created, limit=4'); and here is how I do it now : $pages->find('template=news,!news_date>today, sort=-created|-news_date, limit=4'); The only issue is that the sort does not sort a big mashup of all the dates regardless of whether it's in "created" or "news_date" but it sorts one and then the other. So what I get is a list of dates like this 02 jul 2015 (news_date) 15 Jul 2014 (news_date) 2 Dec 2014 (created) 1 Nov 2014 (created) The news_date list is on top of the created list. Do you know how I could achieve this? Thanks a lot
  23. Am I right in understanding that there's no way to escape or encode a dash ("-") for use within a selector value (that has to be sanitized)? Looking at the code for $sanitizer it looks like it's just converted to a space. That seemingly makes it impossible to search for terms like "x-ray." Any workarounds for this?
  24. I extended my users-template with a lot af fields? One of them is 'instrument' The code beyond is working fine (see screenshot 1). 'instrument' is a page-select-field in the user template (the pages are violin, cello, clarinet, ...). But this is not nice and efficient coding!! // Violin $person = $users->find('instrument=violin'); echo "violin"; foreach ($person as $p) { // $user fields are shown echo $p->first_name; } // cello $person = $users->find('instrument=cello'); echo "cello"; foreach ($person as $p) { // $user fields are shown echo $p->first_name; } // clarinet $person = $users->find('instrument=clarinet'); echo "clarinet"; foreach ($person as $p) { // $user fields are shown echo $p->first_name; } // and so on With a foreach the code could me more efficient, but the find-selector givns a problem with the variable $instr. // all instrument in a foreach foreach ($user->instrument as $instr){ $person = $users->find('instrument=$instr'); // does not work, neither do find('$instr') and find($instr) echo $instr->title; foreach ($person as $p) { // $user fields are shown echo $p->first_name; } } With $person = $users-find($instr); only the value of $instr is shown (e.g. violin) but not the values of $p (e.g. first name of person. (see screenshot 2) How can I use a variable as find-selector?
  25. Hey guys, I thought I had selectors under control until I ran into this situation. This is my structure of four templates: Articles - Article Authors - Author Article contains a pagefield for author. If I wanted to get all articles written by an author, I can run a selector such as "template=article, author=$authorName". So far so good. Here is where I am stuck: I want to display a list of top 10 authors with the most number of articles written. In other words, I want to write a selector that - finds items with template=author - sorts descending by the count of articles written by author <-- I am unable to formulate this part - limits items to 10 One way to solve this is: Get a count of articles by all authors in a php array. Then sort the resultset by article count and get author names for the top ten in the array. This method can be heavy on both database and php, depending on the number of authors and articles in the system. Is there a selector-only trick to solve this problem? thanks
×
×
  • Create New...