Home › Forums › Calendar Products › Events Calendar PRO › Get Category Event to appears only in Widget
- This topic has 13 replies, 2 voices, and was last updated 11 years, 3 months ago by
Josh.
-
AuthorPosts
-
December 10, 2014 at 11:52 am #914497
fortgordonmwr
ParticipantOkay, my brain is about to explode. I can’t seem to figure this out.
I’m trying to set up one of our Event Categories to only display in a sidebar widget. I found a handy resource to remove a category from the entire array (HERE: https://theeventscalendar.com/support/forums/topic/exclude-category-from-both-gridview-and-listview/), but this also removes it from the widget on the same page.
Is there a way, possibly, where I could exclude the category entirely using the function in the link I provided, but then call it back in a special array just for the list widget? Everything I’ve tried seems to fail.
December 10, 2014 at 9:19 pm #914919Josh
ParticipantHello fortgordonmwr,
Thanks for reaching out to us!
Definitely a strange issue to be having. An initial thought would be to add an additional conditional at the beginning of the function in the linked article that will check that this loop isn’t for the widget however I’m not sure of a conditional that would work and a quick search hasn’t turned up anything useful.
An alternative could be the implementation of a new shortcode available that could be used in a Text Widget on your site. Check out this shortcode where you can define the taxonomies directly and see if that will override the filter being placed on the general calendar.
Let me know if this helps.
Thanks!
December 11, 2014 at 5:04 am #915166fortgordonmwr
ParticipantThanks for the suggestion with the shortcode. Unfortunately though, it didn’t work 🙁
Is it possible to add some kind of ‘exclude’ option within the single-day.php code right before it brings in the Event List? That might do it (at least for calendar view).
Here’s the block of code I’m referring to:
<?php while ( $day['events']->have_posts() ) : $day['events']->the_post(); ?>
<?php tribe_get_template_part( 'month/single', 'event' ) ?>
<?php endwhile; ?>
December 16, 2014 at 7:15 am #919818Josh
ParticipantHello fortgordonmwr,
Thanks for following up with us!
I’m sorry the shortcode solution didn’t work for you. One other thing to try would be to add the “tribe_is_event_query” conditional to the initial snippet that you’re using. This should ensure that function only runs when the main loop of the page is and event display. As long as the widget you’re using isn’t on an event page, it shouldn’t be affected by the original exclusion of the category.
Let me know if this helps.
Thanks!
December 16, 2014 at 7:36 am #919845fortgordonmwr
ParticipantThat’s the problem though, I would want this widget to appear on the sidebar of the event calendar pages. It’s our way of decluttering the calendar by separating our Specials & Deals that last every day for months at a time from the rest of our events.
Is there no way to fine-tune just the query of events that appear on the calendar? Obviously, I could hide the Specials & Deals events with CSS, but that might mess up the limit of events displayed for each day.
December 18, 2014 at 6:51 am #922465Josh
ParticipantHey fortgordonmwr,
I’m sorry the previous solution doesn’t work for your needs.
In reference to your second request where you mention:
Is it possible to add some kind of ‘exclude’ option within the single-day.php code right before it brings in the Event List? That might do it (at least for calendar view).
Here’s the block of code I’m referring to:
<?php while ( $day['events']->have_posts() ) : $day['events']->the_post(); ?> <?php tribe_get_template_part( 'month/single', 'event' ) ?> <?php endwhile; ?>
You could wrap the call to the single event template with an “if( !has_term() )” conditional to exclude a particular category from displaying within your main calendar grid.
Let me know if this helps.
Thanks!
January 8, 2015 at 12:00 pm #930551fortgordonmwr
ParticipantThanks! That helped in removing the events with the “specialsdeals” category from the calendar, but it’s still including them in the overall count per day (the $day[‘daynum’] value). Is there a way to exclude these ‘specialsdeals’ events from this count?
Sorry for all the questions.
January 9, 2015 at 10:59 am #930983Josh
ParticipantHey,
No problem.
You could fix this issue by taking a slightly different approach to filtering out the events of that category. You could use “pre_get_posts” to modify the loop for the widget. Then, within the query args you could exclude that category using a “tax_query“.
This would remove the category as well as keep those posts from contributing to the count of events returned by the query.
Let me know if this helps.
Thanks!
January 13, 2015 at 5:26 am #931939fortgordonmwr
ParticipantWhere in the templates would I use “pre_get_posts”? Would it be within the loop-grid.php template, or would it be in the single-day.php template?
January 13, 2015 at 7:46 pm #932412Josh
ParticipantHey,
You would typically add it to the theme’s ‘functions.php’ file and then target the necessary loops using conditionals. However, thinking back over this thread, one of the issues was that we weren’t able to target the appropriate feeds when both the widget and the calendar were displayed on the same page?
With that being the case, I’m not sure there would be a simple way to get the counts to update properly. I’ll reach out to the rest of the team in the morning, however this maybe a customization that is currently beyond the scope of what we’re able to offer in the forums.
I’ll follow up with what I find out.
Thanks!
January 16, 2015 at 9:15 am #933747Josh
ParticipantHey!
I apologize for the delay. Just wanted to follow up with you on this one.
I haven’t found a solid direction that would get all of the changes that you’re looking for, however there is another member of the team who has been out due to illness that I would like to run this by first thing next week to get a final 0pinion.
Thanks!
January 22, 2015 at 1:47 pm #936379Josh
ParticipantHey,
Sorry again for the delay.
We went back and reviewed the original snippet to see if there was a clean way to modify it to fit what you’re needing so it’s not a continual attempt to work around the limitations of these other solutions. Here is the modified version (you’ll need to add the appropriate slug and operator for your specific scenario):
add_action( ‘pre_get_posts’, ‘exclude_events_category’ );
function exclude_events_category( $query ) {if ( $query->query_vars[‘eventDisplay’] == ‘upcoming’ || $query->query_vars[‘eventDisplay’] == ‘past’ || $query->query_vars[‘eventDisplay’] == ‘month’ && $query->query_vars[‘post_type’] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars[‘suppress_filters’] ) ) {
$query->set( ‘tax_query’, array(
array(
‘taxonomy’ => TribeEvents::TAXONOMY,
‘field’ => ‘slug’,
‘terms’ => array(‘presentations’),
‘operator’ => ‘IN’
)
)
);
}return $query;
}
We’ve added an additional check to see if we’re on the main query and running if we are. There are some occasional issues with this that we’ve seen in the past where the check has gone outside the scope of the main query. Let me know if this works with your scenario.Thanks!
-
This reply was modified 11 years, 3 months ago by
Josh.
January 23, 2015 at 5:26 am #936673fortgordonmwr
ParticipantThat did it! I had to make one small adjustment though and change the “IN” operator to “NOT IN” so that it was excluded from the calendar. Now it only displays in the sidebar widget, which is exactly what we were looking for! Thanks so much for your help and your patients with me 🙂
Also, just a side note, I copied the text from your previous post, but had to change all the “smart quotes” to “straight quotes”. I’m pasting my code below so that others who may need this won’t run into the same issue:
add_action( 'pre_get_posts', 'exclude_events_category' );
function exclude_events_category( $query ) {if ( $query->query_vars['eventDisplay'] == 'upcoming' || $query->query_vars['eventDisplay'] == 'past' || $query->query_vars['eventDisplay'] == 'month' && $query->query_vars['post_type'] == TribeEvents::POSTTYPE && !is_tax(TribeEvents::TAXONOMY) && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => TribeEvents::TAXONOMY,
'field' => 'slug',
'terms' => array('presentations'),
'operator' => 'NOT IN'
)
)
);
}return $query;
}
January 23, 2015 at 8:42 pm #936997Josh
ParticipantHey!
Awesome, I’m glad that worked for ya!
Also, thanks for repasting that snippet. I didn’t notice that my original post lost the code block when pasting.
I’ll go ahead and close this ticket. If you have any further questions, please don’t hesitate to open a new one.
Thanks!
-
This reply was modified 11 years, 3 months ago by
-
AuthorPosts
- The topic ‘Get Category Event to appears only in Widget’ is closed to new replies.
