The goal is that when you are on our /upcoming-events page you can then filter by type of event or region.
After you select the option from the dropdown, I want to echo in that page title into the breadcrumb. For example if you wanted to see events near you in Palo alto, you would select Northern California. Here is the code for that selection
<a class="dropdown-item" href="<?= $full_uri . "?tag=northern-california" ?>">
Northern California
</a>
If you found no events near you, you could select the entire state.
<a class="dropdown-item" href="<?= $full_uri . "?tag=california" ?>">
California
</a>
Or if you were available to travel anywhere, you could select by event (in an additional filter)
<a class="dropdown-item" href="<?= $full_uri . "?tag=seminar" ?>">
Seminar
</a>
I was hoping that it would be solved with is_tag
since the url ends with that tag selected, because that is how the filter is set up to direct you, but it won't work(displays nothing). Only has_tag
works, but the problem is that then every string gets echoed for each tag, in this case the region, state, and event type. Here is my php to echo the string
if(has_tag( 'northern-california' || 'southern-california' || 'nevada' || 'webinar' || 'seminar' || 'industry-events')) {
echo ' / ' . '<a href="<?php echo $event_tag; ?>"><span class="event-bread">';
}
if(is_tag( 'northern-california' )) {
$event_tag = 'northern-california';
echo "Northern California";
}
if(is_tag( 'northern-california' )) {
$event_tag = 'northern-california';
echo "Northern California";
}
/* other regions omitted for brevity */
if(is_tag( 'seminar' )) {
$event_tag = 'seminar';
echo "Seminars";
}
/* other event types omitted for brevity */
/* i think this below is a sloppy way to close the div */
if(has_tag( 'northern-california' || 'southern-california' || 'nevada' || 'webinar' || 'seminar' || 'industry-events')) {
echo '</span></a>';
}
Update 1
Based on an answer I added this in my functions.php
function event_tag_url() {
add_filter( 'query_vars', function( $eventVars ) {
$eventVars[] = 'eventTag';
return $$eventVars;
}, 10, 1 );
}
Then in my category.php
I changed to a switch statement
switch( get_query_var( 'eventTag' ) ) {
case 'california':
$eventTag = 'california';
echo "California";
break;
case 'northern-california':
$eventTag = 'northern-california';
echo "Northern California";
break;
case 'southern-california':
$eventTag = 'southern-california';
echo "Southern California";
break;
case 'seminar':
$eventTag = 'seminar';
echo "Seminars";
break;
default:
$eventTag = 'all';
break;
}
This is not echoing anything though. and still does not seem like it would solve the problem of what happens when you have multiple tags. I think the solution should look for what tag the page is set to?
add_filter()
function wrapped inside of another function. Your filter will not be added unless you call that function before WP tries to filterquery_vars
. Also, you're returning$$eventVars
. There's an extra $ which will return nothing since ${$eventVars} doesn't exist.