Use post categories as event categories
-
Is it possible to use the categories i already use with my posts with the event categories? I want to show a calendar with events per post category.
-
Apologies, but I’m having a little trouble understanding your goal. Can you please provide an example or clarify further?
may he don’t want to enter the categories twice…?
Exactly. I don’t want to enter categories twice.
I have a category template page which shows all posts from that category. But i need to add a event calendar in that category template as well. So i want add the event calendar by shortcode and have the template fill in the category for that dynamically. But i need post categories for that to be able to that. I don’t have control over those categories as some might added or removed in the future.
Although that’s not possible by default, you may be able to do it using something like this:
https://wp-events-plugin.com/tutorials/using-additional-custom-taxonomies/
-Update-
Adding the post categories to Event Manager with the info in that link works like a charm! Thanks for that.Only one problem left now. That shortcode thing described on that page isn’t working for me. I registered the taxonomy for EM_POST_TYPE_EVENT and event-recurring, but not locations (i don’t need that).
The provided code on that page isn’t working for me:
echo EM_Events::output( array('post_category'=>'post-category-slug-here') );
Instead i did this:
echo do_shortcode( '[events_list post_category=”post-category-slug-here”]' );
No errors this time, but it’s not showing the category i provided. I just get a No events found message instead.How to fix that?
- This reply was modified 6 years, 12 months ago by Borneyak.
Another question i got:
Are there shortcodes for custom taxonomies? Like #_EVENTNAME, but then to call custom taxonomies like the Post Category example?If you try using your code as a standard shortcode in a page or post does it work correctly?
Custom taxonomies can be used in shortcodes as described under “Using Custom Taxonomies in searches” here:
https://wp-events-plugin.com/tutorials/using-additional-custom-taxonomies/
The shortcode works. It was an error on my side. Probably a copy-paste error…
It works now.I need a #-shortcode (or something different) to use inside Event Manager’s event page template styling.
(Darn… I hate it when i can’t edit older posts here… ?? )
The shortcode works as in it serves me events, but it does not recognize the slug i entered.
This is not working. This serves me a PHP error…
echo EM_Events::output( array( 'post_category'=>'this_is_my_slug' ) );
This is not working either, but this time it says it cant find any events:
echo EM_Events::output( array( 'post_category'=>'this_is_my_slug' ) );
This works, but has nothing defined:
echo EM_Events::output();
How can i get this working?
What PHP error are you seeing?
Hi Borneyak,
Here’s a snippet that works like a charm ??
It will take your normal categories (as used in posts and adds them to the Events Manager admin menu column as well as a meta box on the side of your even edit pages. They are not copied, simply “shown also”.
If you add a category either in Posts or Event, it will be available everywhere instantly.// Use 'normal' Blog Categories in Events Manager function em_customcode_use_blog_categories(){ $supported_array = (EM_MS_GLOBAL && !is_main_site()) ? array():array(EM_POST_TYPE_EVENT,'event-recurring'); register_taxonomy_for_object_type('category',EM_POST_TYPE_EVENT); } add_action('init','em_customcode_use_blog_categories',100);
If you want to rename the Menu label, you can use this. On MultiSite the Event Categories have the same name as the Blog Categories in the meta boxes, so that might be confusing. This snippets solves that for you.
// Rename 'normal' Blog Categories, so the difference is clear between Events Categories on the main blog. function em_customcode_rename_blog_categories() { global $submenu; $submenu['edit.php'][15][0] = __('Blog Categories', 'your_textdomain'); // You need to customize the Label and textdomain } add_action( 'init', 'em_customcode_rename_blog_categories' );
Just paste these into your function.php
Hope it works for you as well. ??Oh, a little addition…. ??
The Blog Categories are separate from the Event Categories, so they cannot be called using #_CATEGORYNAME. You’d have to use the same php coding as in posts and pages to echo the blog categories.
You needed a custom placeholder for these blog categories? No problem! LOL. ??
Note: Placeholders are case sensitive. You can change $result == ‘#_ANYTHINGYOUWANT’// Create #_ccBlogCategory Placeholder add_filter('em_event_output_placeholder', 'cc_output_blog_category', 1,3) ; function cc_output_blog_category($replacement, $EM_Event, $result) { if ($result == '#_ccBlogCategory') { global $EM_Event; foreach ( (get_the_category()) as $category ); $replacement = $category->cat_name; } return $replacement; }
SORRY!
The placeholder only works on the single event page. It will cause errors in the calendar etc. I will look into that.
- The topic ‘Use post categories as event categories’ is closed to new replies.