• Resolved Robin John

    (@johnymon)


    Hi Stephen,

    Here is what I did

    Installed WP 3.4, added Event Organiser plugin, enabled permalinks in WP and the plugin area, Created several post under events with category,venue.

    The permalinks worked fine –
    https://localhost/website/things-to-do
    https://localhost/website/things-to-do/meeting
    [things-to-do = Events,meeting = category]

    Then I rquired couple of custom post type with taxonomy, so i added them in function.php.

    Here is the issue :
    After adding the custom post type, permalinks for Event section stopped working, it giving 404 page. Disabling permalinks from the event organiser area solves the issue but with ugly url’s https://localhost/website/?event-category=meeting

    Code added in function.php for custom post type with taxonomy is as follows

    $labels = array(
        'name'                          => 'Category',
        'singular_name'                 => 'Category',
        'search_items'                  => 'Search Category',
        'popular_items'                 => 'Popular Category',
        'all_items'                     => 'All Category',
        'parent_item'                   => 'Parent Category',
        'edit_item'                     => 'Edit Category',
        'update_item'                   => 'Update Category',
        'add_new_item'                  => 'Add New Category',
        'new_item_name'                 => 'New Category',
        'separate_items_with_commas'    => 'Separate Category with commas',
        'add_or_remove_items'           => 'Add or remove Category',
        'choose_from_most_used'         => 'Choose from most used Category'
        );
    
    $args = array(
        'label'                         => 'Category',
        'labels'                        => $labels,
        'public'                        => true,
        'hierarchical'                  => true,
        'show_ui'                       => true,
        'show_in_nav_menus'             => true,
        'args'                          => array( 'orderby' => 'term_order' ),
        'rewrite'                       => array( 'slug' => 'offers', 'with_front' => false ),
        'query_var'                     => true
    );
    
    register_taxonomy( 'offers-category', 'offers', $args );
    
    register_post_type( 'offers',
        array(
            'labels'                => array(
                'name'              => __( 'Offers' ),
                'singular_name'     => __( 'Offers' )
                ),
            'public'                => true,
            'show_ui'               => true,
            'show_in_menu'          => true,
            'supports'              => array( 'title','editor','thumbnail', 'excerpt' ),
            'rewrite'               => array( 'slug' => 'offers/%offers-category%', 'with_front' => false,'hierarchical' => true ),
            'has_archive'           => true,
    		'query_var'				=> true
        )
    );
    
    function filter_post_type_offers($link, $post)
    {
        if ($post->post_type != 'offers')
            return $link;
    
        if ($cats = get_the_terms($post->ID, 'offers-category'))
            $link = str_replace('%offers-category%', array_pop($cats)->slug, $link);
        return $link;
    }
    add_filter('post_type_link', 'filter_post_type_offers', 10, 2);

    Stephen, Can you point out what am I doing wrong ?? ?

    https://www.ads-software.com/extend/plugins/event-organiser/

Viewing 1 replies (of 1 total)
  • Thread Starter Robin John

    (@johnymon)

    I figured it out, was using flush_rewrite_rules(); after the custom post type with taxonomy code in function.php .

    Just removed it and it works fine now.

    Thanks for the great plugin \m/

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Event Organiser] Permalinks not working after adding custom post type with taxonomy’ is closed to new replies.