Jump to content

Archived

This topic is now archived and is closed to further replies.

jenkyjay

Wordpress 3.1 Custom Post Type Permalink Problem

Recommended Posts

Hi,

 

I have 3 custom post types setup and I have created a custom permalink structure for each. The problem I am having is that the third custom post type I have setup with the custom permalink, is being used for the previous 2.

 

Example:

 

    Classified

    Employment

    Sponsorship

 

The above are the post types and I have the custom permalink structure set to (for each): /post_type/post_id/

 

Now, The above order are the order they are set in and sponsorship takes over all of them. So for instance:

 

/classified/100/

/employment/101/

/sponsorship/102/

 

The above all use the permalink:

 

/sponsorship/100/

/sponsorship/101/

/sponsorship/102/

 

What am I doing wrong to get this error happening? Is it a permalink structure error? below is my code I am using to create the custom permalink structures for each. The only difference is that %c_id% is changed to %e_id% and %s_id% for classifieds, employment and sponsorship. And also any reference to 'classifieds' is changed to employment and sponsorship respectively.

add_action('init', 'classifieds_rewrite');
function classifieds_rewrite() {
    global $wp_rewrite;

    $queryarg = 'post_type=classifieds&p=';
    $wp_rewrite->add_rewrite_tag('%c_id%', '([^/]+)', $queryarg);
    $wp_rewrite->add_permastruct('classifieds', '/classifieds/%c_id%/', false);
}

add_filter('post_type_link', 'classifieds_permalink', 1, 3);
function classifieds_permalink($post_link, $id = 0) {
    global $wp_rewrite;
    $post = &get_post($id);
    if ( is_wp_error( $post ) )
        return $post;
    $newlink = $wp_rewrite->get_extra_permastruct('classifieds');
    $newlink = str_replace("%c_id%", $post->ID, $newlink);
    $newlink = home_url(user_trailingslashit($newlink));
    return $newlink;
}

 

Thanks for the help! :)

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.