• Resolved rjrp

    (@rjrp)


    Hi,
    I’m having issues, I created a custom post type called Projects, and a custom taxonomy called Project Category.

    I want my posts to have the url /%project_category%/test/ but seems it’s not working. How can I accomplish that?

    Thanks.

    The page I need help with: [log in to see the link]

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

    (@tw2113)

    The BenchPresser

    Do you have an example of a single post in this post type that is working, as compared to what you’re aiming for?

    My guess at the moment is that the taxonomy isn’t being included in the single post url like you’re wanting. However, what you’re sounding like you are aiming for looks more like it’s interpreting “test” as a taxonomy term and not a post type slug as well.

    Thread Starter rjrp

    (@rjrp)

    The url now it’s https://odgarchitects.flywheelsites.com/cat/test/

    cat – is a category
    test – post

    I was able to make it work using the code below and adding %project_category% on the rewrite field on the CPT, just wondering if could get to that just using the plugin

    function write_projects_permalinks( $post_link, $post ){
        if ( is_object( $post ) && $post->post_type == 'projects' ){
            $terms = wp_get_object_terms( $post->ID, 'project_category' );
            if( $terms ){
                return str_replace( '%project_category%' , $terms[0]->slug , $post_link );
            }
        }
        return $post_link;
    }
    add_filter( 'post_type_link', 'write_projects_permalinks', 1, 2 );
    
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    We do have the “rewrite slug” option available, but beyond that, I probably would have suggested a similar solution to what you already found. CPTUI doesn’t do anything in the areas of permalink customization, outside what to use as the slugs for post types and taxonomies.

    Thread Starter rjrp

    (@rjrp)

    So I am doing it the right way, there is no way to do this just with the plugin and the rewrite field?

    Thanks for all your support.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Yes, I believe so.

    A “just in case” thought, if the post has multiple categories, then what you have above will only utilize the first category term found.

    Thread Starter rjrp

    (@rjrp)

    Seems that it stopped working and now my sitemap shows a https://odgarchitects.flywheelsites.com/%project_category%/

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Posted almost exactly at the same time as me.

    You’re on the more right path, though it needs some tweaking. It’s still details we don’t cover with CPTUI itself, and external code is needed. CPTUI handles the registration, hopefully really well for peoples needs, but not much beyond that.

    Thread Starter rjrp

    (@rjrp)

    Thanks Michael for your support!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Category Slug’ is closed to new replies.