Changing the event slug/permalink

Changing the event slug/permalink
In Event listings WP Event Manager default to the permalink ‘events’. So, for example, an event may have the following URL: http://yoursite.com/events/event-listing-title Two methods in customising this;
  1. Using a localization file and translating the string
  2. Using a filter

Important note: To make the slug functional, you will have to save it again after the change. Go to admin panel and Click on Permalinks under Settings menu. Select any Common Settings options and press save button.

 
Changing the event slug
 
Use Filters to change the permalink base
Add some custom code to your theme functions.php to filter the permalink:
<?php 
function change_event_listing_slug( $args ) 
    { 
        $args['rewrite']['slug'] = _x( 'events', 'Event permalink - resave permalinks after changing this', 'wp-event-manager' ); 
        return $args; 
    } 
    add_filter( 'register_post_type_event_listing', 'change_event_listing_slug' ); 
?>
 
Change the permalink slug for new events
To make event permalinks extraordinary, the slug has organizer and event location names appended to it. You can alter this through a filter and custom function added to your theme functions.php file. The code used is as follows:
<?php 
function custom_submit_event_form_save_event_data( $data, $post_title, $post_content, $status, $values ) 
    { 
        $event_slug = array(); 
        // Prepend with organizer name 
        if ( ! empty( $values['organizer']['organizer_name'] ) ) 
            $event_slug[] = $values['organizer']['organizer_name']; 
        // Prepend location if ( ! empty( $values['event']['event_location'] ) ) 
            $event_slug[] = $values['event']['event_location']; 
            $event_slug[] = $post_title; $data['post_name'] = implode( '-', $event_slug ); return $data; 
    } 
    add_filter( 'submit_event_form_save_event_data', 'custom_submit_event_form_save_event_data', 10, 5 ); 
?>
 
Example: Adding the Event ID to the base URL
The event ID will be added to the base URL with the help of this snippet.E.g. /event/1234/event-title
<?php function event_listing_post_type_link( $permalink, $post ) { // Abort if post is not a event if ( $post-&gt;post_type !== 'event_listing' )
        return $permalink;

    // Abort early if the placeholder rewrite tag isn't in the generated URL
    if ( false === strpos( $permalink, '%' ) )
        return $permalink;

    $find = array(
        '%post_id%'
    );

    $replace = array(
        $post->ID
    );

    $replace = array_map( 'sanitize_title', $replace );

    $permalink = str_replace( $find, $replace, $permalink );

    return $permalink;
}
add_filter( 'post_type_link', 'event_listing_post_type_link', 10, 2 );

function change_event_listing_slug( $args ) {
  $args['rewrite']['slug'] = 'event/%post_id%';
  return $args;
}
add_filter( 'register_post_type_event_listing', 'change_event_listing_slug' );
 ?>
 
Example: Add the category to the base URL
The Event’s category name is added to the base url with the help of this snippet. E.g./event/event-category/event-title
<?php function event_listing_post_type_link( $permalink, $post ) { // Abort if post is not a event if ( $post-&gt;post_type !== 'event_listing' )
        return $permalink;

    // Abort early if the placeholder rewrite tag isn't in the generated URL
    if ( false === strpos( $permalink, '%' ) )
        return $permalink;

    // Get the custom taxonomy terms in use by this post
    $terms = wp_get_post_terms( $post-&gt;ID, 'event_listing_category', array( 'orderby' =&gt; 'parent', 'order' =&gt; 'ASC' ) );

    if ( empty( $terms ) ) {
        // If no terms are assigned to this post, use a string instead (can't leave the placeholder there)
        $event_listing_category = _x( 'uncat', 'slug' );
    } else {
        // Replace the placeholder rewrite tag with the first term's slug
        $first_term = array_shift( $terms );
        $event_listing_category = $first_term-&gt;slug;
    }
    
    $find = array(
        '%category%'
    );

    $replace = array(
        $event_listing_category
    );

    $replace = array_map( 'sanitize_title', $replace );

    $permalink = str_replace( $find, $replace, $permalink );

    return $permalink;
}
add_filter( 'post_type_link', 'event_listing_post_type_link', 10, 2 );

function change_event_listing_slug( $args ) {
  $args['rewrite']['slug'] = 'event/%category%';
  return $args;
}
add_filter( 'register_post_type_event_listing', 'change_event_listing_slug' );
 ?>
 
Example: Adding the category and event location to the base URL
This snippet would add the category name and event location name to the base url. E.g. /event/event-category/event-location/event-title
<?php function event_listing_post_type_link( $permalink, $post ) { // Abort if post is not a event if ( $post-&gt;post_type !== 'event_listing' ) {
        return $permalink;
    }

    // Abort early if the placeholder rewrite tag isn't in the generated URL
    if ( false === strpos( $permalink, '%' ) ) {
        return $permalink;
    }

       // Get the custom taxonomy terms in use by this post
    $categories = wp_get_post_terms( $post-&gt;ID, 'event_listing_category', array( 'orderby' =&gt; 'parent', 'order' =&gt; 'ASC' ) );
    $locations = wp_get_post_terms( $post-&gt;ID, 'event_listing_location', array( 'orderby' =&gt; 'parent', 'order' =&gt; 'ASC' ) );       

    if ( empty( $categories ) ) {
        // If no terms are assigned to this post, use a string instead (can't leave the placeholder there)
        $event_listing_category = _x( 'uncategorized', 'slug' );
    } else {
        // Replace the placeholder rewrite tag with the first term's slug
        $first_term = array_shift( $categories );
        $event_listing_category = $first_term-&gt;slug;
    }

    if ( empty( $locations) ) {
        // If no terms are assigned to this post, use a string instead (can't leave the placeholder there)
        $event_listing_location = _x( 'anywhere', 'slug' );
    } else {
        // Replace the placeholder rewrite tag with the first term's slug
        $first_term = array_shift( $locations);
        $event_listing_location = $first_term-&gt;slug;
    }

    $find = array(
        '%category%',
        '%location%'
    );

    $replace = array(
        $event_listing_category,
        $event_listing_location
    );

    $replace = array_map( 'sanitize_title', $replace );

    $permalink = str_replace( $find, $replace, $permalink );

    return $permalink;
}
add_filter( 'post_type_link', 'event_listing_post_type_link', 10, 2 );

function change_event_listing_slug( $args ) {
  $args['rewrite']['slug'] = 'event/%category%/%location%';
  return $args;
}
add_filter( 'register_post_type_event_listing', 'change_event_listing_slug' );

function add_location_endpoint_tag() {
    add_rewrite_tag( '%location%', '([^/]*)' );
}
add_action( 'init', 'add_location_endpoint_tag' );
 ?>