Search the Community

Showing results for tags 'selector'.



More search options

  • 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

Found 75 results

  1. 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?
  2. 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 " }
  3. 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 .
  4. 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!
  5. <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?
  6. How to merge selectors of different types (string, array, array of arrays, Selectors) and get $selector with some of these types (to pass it to $pages->find($selector))?
  7. 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.
  8. 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.
  9. I'm trying to show upcoming calendar posting pages that have an event_start_datetime and an event_end_datetime. The listing should show calendar postings greater than or equal to today (no past events unless it has an event_end_datetime that is within 3 days after today) if the calendar posting has an event_end_datetime and is within 3 days of today it should still show even though the event_start_datetime has passed. Ex. an event that spans Wed-Saturday. If today is Friday, I still want to show the event on my calendar. Here is the code I have tried: $date = date("Y-m-d");// current date $date_start = strtotime( date('Y-m-d') . " 00:00:00"); $date_end = strtotime(date("Y-m-d", strtotime($date)) . " +1 week"); $paginated_calendar_postings = $pages->get("/calendar")->children("template=calendar-posting|community-event,event_start_datetime>=$date_start, event_end_datetime<=$date_end, sort=-event_start_datetime"); But that doesn't return the correct results. I've spent all day searching through the forums, but couldn't find an answer. Any help is appreciated. Also is there anyway to format your selector on multiple lines like this: $paginated_calendar_postings = $pages->get("/calendar")->children( "template=calendar-posting|community-event, event_start_datetime>=$date_start, event_end_datetime<=$date_end, sort=-event_start_datetime"); It would make it easier to read long selectors. When I tried it, it didn't work. I think it even gave the wrong results.
  10. 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 !
  11. 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>";
  12. 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!
  13. 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é
  14. 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
  15. 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?
  16. 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
  17. 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?
  18. 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?
  19. 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
  20. Hej, i am trying to build a custom PHP code selector to get all pages using a user template for a site using multiple templates for users. Here are my two non-working approaches: /** * A */ return function() { $template_ids = implode("|", $config->userTemplateIDs); return $pages->find("template=$template_ids, include=all"); }; /** * B */ return $pages->find("template=".implode("|", $config->userTemplateIDs).", include=all"); Maybe I am thinking too complicated and I miss something here - basically I need a Page Field which can select from all users with all the different user templates ... uhm - has anyone an idea how this might work? Also in general - has anyone an idea what is actually possible with this custom php code selector? I guess it is somewhat restrained? Thanks! Steffen EDIT: I guess that I can't access $config?
  21. I have an event page were you can select multiple sub-categories with a page field using checkboxes. Now i want to display all the sub-categories but also have them sorted by their parent category. I tried something lik below but that didn't work. $tags = $event_cat->find("sort=$event_cat->parent"); foreach ($tags as $tag){ echo $tag; } Any ideas?
  22. Hello together, I have the following search routine to find pages containing one or more ZIP codes. postleitzahlen.plz is the selector and is a repeater.value The following code works fine and finds all pages that contain the (German) ZIP codes in my test string $p_test $p_test="40489|40822|40878|40880|40882|40883"; $selector = "template=print, title|job_body|job_body_2|job_body_3%=" . implode("|", $suche_1) . "; $selector .= ", id=[postleitzahlen.plz=".$p_test."]"; $matches = $pages->find($selector); My problem is, I do not have 6 numbers in $p_test, I have a lot more. In the worst case scenario I could have around 1500 ! If I have more then 80 numbers in my $p_test I got an error message: Error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? Is there a limit in having too much selectors? Thanks, Thomas
  23. In reference to http://processwire.com/api/fieldtypes/repeaters/ is it possible to say 'where all repeater items' rather than 'where at least one repeater item' inside your selector? What I have is a repeater with a checkbox. I want to find pages where all repeater items on the page are checked or unchecked. If I do this: $pages->find("my_repeater.my_checkbox>1"); I get pages where at least one repeater item has the checkbox ticked, but what I want is pages where the checkbox is ticked in all of the repeaters.
  24. Hi, I'm having a sorting problem that I need to solve. I have the following code: $today = time(); $trainings = $pages->get('/formacao/')->find("template=training, limit=6, !training_start<$today, sort=training_start"); It's working fine, except for one little problem: I need to show the trainings that have training_start filled first and then the one's that don't. This solution shows the empty ones first! Is there any way to do this with a simple selector? Or do I have to find twice? To understand better: Result that I have now: Footbal: Date not set yet! Ragueby: Date no set yet! Volleyball: 1-Apr-2016 Handball: 5-Apr-2016 Running: 10-Apr-2016 Jumping: 15-Apr-2016 Result needed: Volleyball: 1-Apr-2016 Handball: 5-Apr-2016 Running: 10-Apr-2016 Jumping: 15-Apr-2016 Footbal: Date not set yet! Ragueby: Date no set yet!
  25. Hi Guys, I wanted to find all pages which are children of the current page: $rootPage = $page->children(); But I then want to filter out all pages of a few different templates: $rootPage = $page->children('template!=cta-block|puffs-block|table-block'); But also filter out one specific template called company when the pages website textbox has no value: $rootPage = $page->children('template!=cta-block|puffs-block|table-block')->not('template=company, website='); This doesn't work - I have tried a few different variations, but can't get it right. Anybody point out where I am going wrong? Thanks, Craig