Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Add the start event date in the permalink using the format /YYYY/mm/dd
- * Inspired by http://pastebin.com/v4fT1671
- * For installation instructions, see this tutorial, we recommend adding this to mu-plugins as a separate file:
- * http://wp-events-plugin.com/tutorials/how-to-safely-add-php-code-to-wordpress/
- */
- /**
- * Add the start event date in the permalink
- *
- * @param string $permalink Permalink
- * @param object $post Post object
- * @param boolean $leavename
- * @return string Permalink
- */
- function my_events_manager_get_permalink($permalink, $post, $leavename = false)
- {
- if ($post->post_type == 'event') {
- $event = em_get_event($post->ID, 'post_id');
- $start_date = $event->event_start_date;
- $start_date = str_replace('-', '/', $start_date);
- $event_slug = get_site_option('dbem_cp_events_slug');
- $permalink = str_replace($event_slug, $event_slug . '/' . $start_date, $permalink);
- return $permalink;
- } else
- return $permalink;
- }
- add_filter('post_type_link', 'my_events_manager_get_permalink', 10, 3);
- /**
- * Add a rewrite rule to accept the date in the permalink
- */
- function my_events_manager_add_rules() {
- $event_slug = get_site_option('dbem_cp_events_slug');
- add_rewrite_rule($event_slug . '/\d+/\d+/\d+/(.+)$', 'index.php?post_type=event&name=$matches[1]', 'top'); // single event
- }
- add_action('init', 'my_events_manager_add_rules', 9); // Must be run before events manager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement