Forum
Filtering an event by matching with fields in a separate region
Hi there, I'm making a site that includes concert listings for various artists, following the listing/details tutorial. I've got the listing/details pages working, but am now looking to filter outputted events on the details pages to match the artist of each page.
So as far as I can see ( and I hope the code below demonstrates this ) I need to see if the event ID "artist" matches with the "title" ID in the Artist's array.
I'm having trouble using filter, match and value to find this value however. Anybody any experience with something similar?
<?php include('perch/runtime.php'); ?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Artists</title>
</head>
<body>
<?php
perch_content_create('Artists', array(
'template' => 'artist_detail.html',
'multiple' => true,
'edit-mode' => 'listdetail'
));
?>
<?php
if (perch_get('s')) {
// Detail mode
perch_content_custom('Artists', array(
'template' => 'artist_detail.html',
'filter' => 'slug',
'match' => 'eq',
'value' => perch_get('s'),
'count' => 1
));
perch_events_custom('Artists', array(
'past-events' => false,
'filter' => 'title',
'match' => 'eq',
'value' => perch_get('s')
));
perch_layout('global.bottom');
} else {
// List mode
perch_content_custom('Artists', array(
'template' => 'artist_listing.html'
));
}
?>
</body>
</html>
Here's how I declare the artist names in the 'Artists' region:
<h1><perch:content id="title" type="text" label="Artist Name" required="true" title="true" /></h1>
And here's my events template.
<div class="table-row col-lg-12">
<div class="table-left">
<h4 class="date-day">
FRI
</h4>
<h3 class="date-number">08</h3>
<h4 class="date-month">JUL</h4>
</div>
<div class="table-right">
<h4 class="venue"><a href="nathan-carter.html">
<perch:events id="artist" label="Artist List" type="dataselect" page="*" region="Artists" options="title"/>
</a></h4>
<a class="special-event" href="">
<perch:events id="venue" encode="false" label="Venue" />
</a>
</div>
</div>
If
perch_get('s')
holds the artist slug, you might be better storing that against the eventthen you'd be able to use
Hi Drew. When I try that code, the event template shows up empty, and I can't seem to figure out why.
So my region/field ID structure is like this:
I'm looking to compare the value of 'title' in the Artist's region with the value of 'artist' in events.
When I get to, for example the following URL:
site/artists.php?s=tome-johannes
The artist title is output in artist_detail.html like so:
But where the events are output, nothing shows up. I have replaced the code in the events template with the code you provided.
When I leave the perch_events_cutom('Artists', array()); function completely blank, it outputs all events, not filtered by the slug, and echoes the slug of an artists title rather than their name. Even adding 'past-events' => false seems to stop any output. If I then delete values="slug" from the events template, the events go back to not outputting.
Thanks for the response by the way, having real trouble with filter, match and value and it's pretty essential for this project.
Can you clarify what you're seeing? If you turn debug on, do you get any output? If not, have you checked your error log?
Okay I just found a mistake I was making regarding the event template, I was calling artist instead of output. So updated event.html:
And what I'm seeing is here: https://imgur.com/a/iSaRj
Debug Log
Is your filter now working? What problem are we trying to solve?
The problem is that the filter isn't working. When I try to filter the output with this code:
The events return blank, without showing the artist name, as shown in this image here: https://imgur.com/a/GfL18
If you turn on debug, what does it output?
Debug Message here:
Diagnostics if that's of any use:
Ah, if this is filtering Events, then I don't think it's going to work. The Events app is very elderly and doesn't support filtering by dynamic fields - you can only filter the predefined fields.
So there is no way to categorize events? Or can I restructure the site and hardcode the values in? Do the 'name' and 'description' properties count as dynamic, as in can I only filter by date?
Events can have categories, yes.
You can filter on the title, slug, date/time, description, URL.
Hi Drew, Thanks for looking into this. Given that the events app can't filter by custom dynamic fields I've decided to use perch custom content and am making headway with that. Thanks!