Jump to content

Wordpress 3.1 Custom Post Type Permalink Problem


jenkyjay

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! :)

 

  • 3 months later...

Hi did you find out a solution?

 

I think the problem is down to this line:

 

$newlink = $wp_rewrite->get_extra_permastruct('classifieds');

 

I too am stuck on this now, it looks like it wasn't developed to alter permalink changes to more than one post type?

Archived

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

×
×
  • 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.