• Resolved Xavvi

    (@skinny-latte)


    Hi,

    I have a cpt of ‘Information’ and an associated taxonomy of ‘info_category’. I want my URLs to read information/in-depth/postname where ‘in-depth’ is the taxonomy.

    I have set the custom rewrite slug to information/%info_category%. But in the admin area for Information articles the slug just shows information/%info_category%/ and so the links are broken.

    Any idea how to fix?

    Any help appreciated

    Thanks

    https://wordpress.org/plugins/custom-post-type-ui/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    First question is if you flushed your permalinks after creating. If not, try that first. If you’re still having issues afterwards, let me know and I can think it through some more for any ideas.

    Thread Starter Xavvi

    (@skinny-latte)

    Yes I tried that. No luck unfortunately

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Is this custom rewrite slug being set on the permalinks page? or the CPTUI settings for that taxonomy?

    I’m curious if this permalink structure is going to take some custom snippets of code to help with parsing as well. We don’t offer every single part of the process in our plugin for the variety of permalinks that people want, we just provide the fields needed for at the point of registration.

    Thread Starter Xavvi

    (@skinny-latte)

    The rewrite slug is being set in the CPTUI settings for the taxonomy.

    I’ve managed to get it working but only by setting up the custom post type manually in my functions file and using the following string replace function:


    add_filter('post_link', 'information_permalink', 10, 3);
    add_filter('post_type_link', 'information_permalink', 10, 3);

    function information_permalink($permalink, $post_id, $leavename) {
    if (strpos($permalink, '%info_category%') === FALSE) return $permalink;

    // Get post
    $post = get_post($post_id);
    if (!$post) return $permalink;

    // Get taxonomy terms
    $terms = wp_get_object_terms($post->ID, 'info_category');
    if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) $taxonomy_slug = $terms[0]->slug;
    else $taxonomy_slug = 'info_category';

    return str_replace('%info_category%', $taxonomy_slug, $permalink);
    }

    I tried using just the string replace with the post type set up using the plugin but it didn’t work, presumably because the functions file is being called before the plugin or something?

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Cool. Yeah, those filters you used aren’t something we provide any sort of UI for, so going that route is the best idea. I am curious why it didn’t work when having our plugin do the registration though.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Custom rewrite slug issue’ is closed to new replies.