Jump to content

Wordpress 3.1 Custom Post Type Permalink Problem


Recommended Posts



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.








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:






The above all use the permalink:






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


Link to comment
Share on other sites

  • 3 months later...
This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


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