Jump to content

Recommended Posts

Hi there,

I have a bit of trouble on filtering correctly some event pages by some selectors...

I do have the following 2 date fields:
- start date (fieldname = date)
- end date (fieldname = enddate)

Some events are a single day event (only start date) - some are a multi day event (end date).
Past single day events should not show up.
Current multi day events should show up (even if start day is in the past, but end date is future).

So I have the following selector:

if ($standort == '') {
	$termine = $page->children("sort=date, limit=10, (date>=today, enddate=''), (enddate>=today)");
} else {
	$termine = $page->children( "(standort_reference~=$standort), (standort_alle=1), (date>=today, enddate=''), (enddate>=today), sort=date, limit=10");
}

This selector

$termine = $page->children("sort=date, limit=10, (date>=today, enddate=''), (enddate>=today)");

works fine, but the follwing does not work (all past entries are also shown):

$termine = $page->children( "(standort_reference~=$standort), (standort_alle=1), (date>=today, enddate=''), (enddate>=today), sort=date, limit=10");

I have no clue what I'm missing - any ideas?

Share this post


Link to post
Share on other sites

You're using OR-groups, which means only one of the selectors in parentheses needs to match. This means if standort_reference or standort_alle match for a page, the other selectors don't matter. If you remove the parentheses around the selectors for standort_reference and standort_alle, the selector should work as intended. Alternatively, use named OR-groups if you want to use multiple groups of alternative selectors in your query:

https://processwire.com/docs/selectors/#or-groups

  • Like 2

Share this post


Link to post
Share on other sites

Thank you @MoritzLost for your reply ๐Ÿ‘.

I had a look at theย OR-groups before, but I don't get it. As I understand by now - as you mentioned, if one OR fits, the other selectors then don't matter. So, my logic is wrong...

When I remove as mentioned the parenthesis for "standort_reference" and "standort_alle", I don't get any output anymore. ๐Ÿ˜ง

Actually I need to filter "$termine" twice:

-> standort_reference OR standort_alle
(standort_reference~=$standort), (standort_alle=1)

One of both above has to match - and additionally then

-> filter for both
(date>=today, enddate=''), (date!='', enddate>=today)

get all single day entries where "date" is only in the future AND additionally also all multi day events which are still present running ("date" in past and "enddate" in the future).

The part of "named groups" I do currently not understand how to get use of it in my part of code ๐Ÿ™ˆ:

foo=(selector1), bar=(selector2), foo=(selector3), bar=(selector4)

Share this post


Link to post
Share on other sites

I think I got it... It works now by the following:

$termine = $page->children("standort=(standort_reference~=$standort), standort=(standort_alle=1), date=(date>=today, enddate=''), date=(date!='', enddate>=today), sort=date, limit=10");

At least It looks like the output is correct!๐Ÿ™

  • Like 2

Share this post


Link to post
Share on other sites
4 minutes ago, flydev ๐Ÿ‘Š๐Ÿป said:

Try range() in your selectorย :


$selector = "range=(date>=1583017200, date<=1589493599)";

just replace the timestamps with your own.

Thank you.
Yeah, that's what I did now, as I do understand the "named groups" now correctly... my code looks finally now:

if ($standort == '') {
	$termine = $page->children("sort=date, limit=10, date=(date>=today, enddate=''), date=(enddate>=today)");
} else {
	$termine = $page->children("standort=(standort_reference~=$standort), standort=(standort_alle=1), date=(date>=today, enddate=''), date=(date!='', enddate>=today), sort=date, limit=10");
}

So I grouped by 2x date() and 2x by standort().

Is that correct coded now? Just to know, that I did understand it right.

  • Like 1

Share this post


Link to post
Share on other sites
18 hours ago, Bacelo said:

So I grouped by 2x date() and 2x by standort().

Is that correct coded now? Just to know, that I did understand it right.

Yes, that looks good! In both of the named groups, at least one of the selectors has to match for the entire group to match, like you wanted.

  • Thanks 1

Share this post


Link to post
Share on other sites
26 minutes ago, MoritzLost said:

Yes, that looks good! In both of the named groups, at least one of the selectors has to match for the entire group to match, like you wanted.

Thank you @MoritzLost ๐Ÿ‘

If I got it right, named groups are actually more then a OR selector, because (in my case) both selectoras will work. So it's more like a OR-AND selector.

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Flashmaster82
      Hi, i need some help with the filtering based on the Skyscrapers demo/func. Iยดm not that great with php so be patient.
      My structure looks like this
      Youtube videos > Youtube channel > Video
      on the video template (youtube_channel_video) i have multiple drop down fields and other fields that i would like to filter on the front end. I also have other pages that need this functions with search/filter etc but with different filters.
      ย 
      This is the code i have in my search-form.php. Right now i experimenting with the field/option (category) that every video have in their template. The first filter (youtube_channel) works but im trying to get the category filter to work.
      <div id='skyscraper-search' class='uk-panel uk-panel-box xuk-panel-box-primary uk-margin-bottom'> <h3 class='h3'>Youtube videos</h3> <form class='uk-form uk-form-stacked' method='get' action='<?php echo $config->urls->root?>search/'> <div class='row'> <label class='uk-form-label' for='search_keywords'>Keywords</label> <div class='uk-form-controls'> <input type='text' class='uk-form-width-large' name='keywords' id='search_keywords' value='<?php if($input->whitelist('keywords')) echo $sanitizer->entities($input->whitelist('keywords')); ?>' /> </div> </div> <div class='col-6'> <div class='row'> <label class='uk-form-label' for='youtube_channel'>Youtube channel</label> <div class='uk-form-controls'> <select id='youtube_channel' name='youtube_channel' class='uk-form-width-large'> <option value=''></option> <?php // generate the youtube_channel options, checking the whitelist to see if any are already selected foreach($pages->find("template=youtube_channel_page") as $youtube_channel) { $selected = $youtube_channel->name == $input->whitelist->youtube_channel ? " selected='selected' " : ''; echo "<option$selected value='{$youtube_channel->name}'>{$youtube_channel->title}</option>"; } ?> </select> </div> </div> </div> <div class='col-6'> <div class='row'> <label class='uk-form-label' for='category'>Category</label> <div class='uk-form-controls'> <select id='category' name='category' class='uk-form-width-large'> <option value=''></option> <?php // generate the category options, checking the whitelist to see if any are already selected foreach($pages->find("template=youtube_channel_video") as $category) { $selected = $category->youtube_video_category == $input->whitelist->youtube_video_category ? " selected='selected' " : ''; echo "<option$selected value='{$category->youtube_video_category}'>{$category->youtube_video_category->title}</option>"; } ?> </select> </div> </div> </div> <div class='uk-margin-top'> <button type='submit' id='search_submit' class='uk-button uk-button-primary' name='submit' value='1'> <i class='uk-icon-search'></i> Search </button> </div> </form> </div> ย 
      This is my search.php
      <?php namespace ProcessWire; $selector = ''; $summary = array( "title" => "", "youtube_channel" => "", "category" => "", "country" => "", ); if($input->get('youtube_channel')) { $youtube_channelName = $sanitizer->pageName($input->get('youtube_channel')); $youtube_channel = pages("/youtube-videos/$youtube_channelName/"); if($youtube_channel->id) { $selector .= "parent=$youtube_channel, "; $summary['youtube_channel'] = $youtube_channel->title; $input->whitelist('youtube_channel', $youtube_channel->name); } } foreach(array('category') as $key) { if(!$value = $input->get($key)) continue; else { $value = (int) $value; $selector .= "$key=$value, "; $summary[$key] = $value; $input->whitelist($key, $value); } } if($input->get('keywords')) { $value = $sanitizer->selectorValue($input->get('keywords')); $selector .= "title|body|category%=$value, sort=title"; $summary["keywords"] = $sanitizer->entities($value); $input->whitelist('keywords', $value); } $videos = findSkyscrapers($selector); $browserTitle = 'Youtube video search - '; foreach($summary as $key => $value) { if($value) { $key = ucfirst($key); $browserTitle .= ucfirst($key) . ": $value, "; } else { unset($summary[$key]); } } region('browserTitle', rtrim($browserTitle, ', ')); region('content', files()->render('./includes/search-summary.php', array('items' => $summary)) . renderSkyscraperList($videos) ); ย 
      This is my skyscraper-list-item.php file
      ย 
      <?php echo " <div class='col-12 col-sm-12 col-md-6 col-lg-6 col-xl-4 col-xxl-4 col-xxxl-4 bmar10'> <div class='youtube_search_holder'> <a data-fancybox data-autoclose='true' data-width='1500' data-height='844' data-height='360' href='{$skyscraper->youtube}autoplay=1'> <div class='youtube_thumbnail_placeholder'><img src='{$skyscraper->youtube_thumbnail->url}' class='youtube_thumbnail_image w-100'> <div class='playicon'></div></div></a> <div class='youtube_search_thumbnail_content'> <div class='h6 text-uppercase green tmar3 title'><a href='{$skyscraper->parent->channel_url}' target='_blank' title='{$skyscraper->parent->title}'>{$skyscraper->parent->title}</a></div><div class='text-uppercase white h3 limit'><a href='{$skyscraper->youtube}' data-fancybox data-width='1500' data-height='844' data-height='360'>{$skyscraper->title}</a></div> <div class='h5 text-uppercase gray date'>{$skyscraper->youtube_video_publishdate}</div> <span class='white h7'> {$skyscraper->youtube_video_category->title} {$skyscraper->countries->title} {$skyscraper->competition->title} {$skyscraper->competition->parent->parent->title} {$skyscraper->armwrestler_competition_gender->title} {$skyscraper->armwrestler_arm->title} {$skyscraper->armwrestler_age_category->title} {$skyscraper->competition_weight_class->title} {$skyscraper->competition_video_match->title} {$skyscraper->videotags} </span> </div></div></div> "; ?> This is the front end right now (no styling ๐Ÿ™‚

      In the category filter, right now there is multiple categories with the same name, i would also like to restrict it to just one result per category.
      Please help!
    • By michelangelo
      Hello there,
      I am building my website, which has a dozen projects with 10 images each. Basically, I need a filtering system but built in the most efficient and user-friendly way. You can see below that the images flow sideways so being hidden, JS lazy loading was a good tool, but I just wanted to try AJAX. Is it fit for this purpose or it's more for dynamic content?
      ย 

    • By Moritz Both
      Greetings,
      when I give users the user-admin-* permission to administer users who have a certain role, they can indeed see and edit those users. However the filter / column panel does not show in the admin interface. How can I enable the filter functionality for user-admin-* members?
      ProcessWire 3.0.123
      Moritz
    • By schwarzdesign
      ProcessWire added the numReferences property in 3.0.107, which returns the count of all pages having a reference to the page object. However, apparently it's not possible to use this property inside a selector. I'm trying to find all pages that are referenced at least once:
      $pages->find('template=service, numReferences>0'); This throws an error: "Field does not exist: numReferences".
      Is there another way to filter by the number of references? Of course, I could manually filter the results of the find query, but that feels overly complicated. Ideally, I would also like to filter the number of references from a specific field; that is, find all pages that are referenced at least once in one specific page reference field.
      Is there a way to do this? I guess supporting numReferences in selectors would be a feature request - if so, is it feasible?
      Thanks!
      ย 
    • 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...