Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to modify the rewrite rules for a custom post type, tribe_events, which is registered as a post type within "The Events Calendar" core plugin files (the-events-calendar.class line 24):

    protected $postTypeArgs = array(
        'public' => true,
        'rewrite' => array('slug' => 'event', 'with_front' => false),
        'menu_position' => 6,
        'supports' => array('title','editor','excerpt','author','thumbnail', 'custom-fields'),
        'capability_type' => array('tribe_event', 'tribe_events'),
        'map_meta_cap' => true
    );

What I would like to do is modify the line:

        'rewrite' => array('slug' => 'event', 'with_front' => false)

To:

'rewrite' => array('slug' => 'event/%lugares%', 'with_front' => false)

Where "%lugares%" is the name of a custom taxonomy.

Then my plan is to use the following function to complete the rewrite process:

add_filter('post_type_link', 'events_permalink_structure', 10, 4);
function events_permalink_structure($post_link, $post, $leavename, $sample)
{
    if ( false !== strpos( $post_link, '%lugares%' ) ) {
        $lugares_term = get_the_terms( $post->ID, 'lugares' );
        $post_link = str_replace( '%lugares%', array_pop( $lugares_term )->slug, $post_link );
    }
    return $post_link;
}

The issue is that I don't want to modify the core plugin files. Is there a way to modify the custom post type rewrite argument in a seperate function from inside my theme's functions.php??

Thanks!

share|improve this question

1 Answer 1

Yes, I believe you can. Paste this code into your theme's functions.php file:

function change_tribe_events_rewrite_rules() {
    global $wp_post_types;
    $rewrite = &$wp_post_types['tribe_events']->rewrite;
    $rewrite['slug'] = 'event/%lugares%';
}
add_action( 'init', 'change_tribe_events_rewrite_rules', 999 );
share|improve this answer
1  
Make sure that you give this a later priority than the original post type is registered with –  Pippin Nov 30 '12 at 1:30
    
@Pippin - Thanks - I've updated the hook for the latest possible priority –  bungeshea_ Nov 30 '12 at 2:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.