• Hi,

    Thank you for a great plugin! We use it with The7 theme, and we’ve experienced it as a great plugin to get out of it what we want so far.

    However, I’m trying to get the same permalink structure as we have on posts. We’ve managed to get /%dt_portfolio_category/%postname%/ working find. However, when we choose categories it won’t show the primary category in the permalink. It rather shows the first one in the alphabet. So if you, for example, want this URL: /energy/this-is-how-you-do-it – it shows this instead: /3d-drawings/this-is-how-you-do-it.

    So the question is how can we get primary category working on custom post type with this plugin?

    Hope to hear from you! We’ve tried to fix this in so many ways…

    Best regards,

    Kjetil

    • This topic was modified 4 years, 8 months ago by kjetilfrdm.
Viewing 3 replies - 1 through 3 (of 3 total)
  • @kjetilfrdm

    In the next version, we will add two new filters cptp_post_link_category and cptp_post_link_term, which will allow you to change the post category or term.

    Any update on this?

    • This reply was modified 4 years, 2 months ago by Gendive.
    Simone

    (@webdesignsimone)

    Hi,
    I had the same problem and i solved it with the new filter cptp_post_link_term to get the primary term by yoast plugin, thanks to the developers!

    I have a Custom Post Type called ‘percorsi’ with 2 custom term ‘cat_sport’ and ‘cat_luoghi’. The setting in CPTP is: /%cat_luoghi%/%cat_sport%/%postname%/
    The resulted URL is correctly it/percorsi/location/sport/title/ but by default the first taxonomy in alphabetical order is taken.

    Since I haven’t found the documentation I ask to the plugin authors if the following code is correct or there is a better way:

    function cptp_term_luogo( $term_obj, $terms, $taxonomy, $post ){
    
        $post_id = $post->ID;
        
        if(get_post_type($post_id) == 'percorsi' && !is_post_type_archive('percorsi') ){
            //SPORT PRIMARIO
            $primary_sport = new WPSEO_Primary_Term('cat_sport', $post_id);
            $primary_sport = $primary_sport->get_primary_term();
            if($primary_sport):
                $sport = get_term($primary_sport);
            endif;
            //LUOGO PRIMARIO
            $primary_luogo = new WPSEO_Primary_Term('cat_luoghi', $post_id);
            $primary_luogo = $primary_luogo->get_primary_term();
            if($primary_luogo):
                $luogo = get_term($primary_luogo);
            endif;
    
            if($taxonomy == 'cat_sport'):
                $term_obj = $sport;
            endif;
    
            if($taxonomy == 'cat_luoghi'):
                $term_obj = $luogo;
            endif;
    
            return $term_obj;  
    
        } else {
    
            return $term_obj;  
    
        }
    }
    add_filter( 'cptp_post_link_term', 'cptp_term_luogo', 10, 4);
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Primary category on custom post types’ is closed to new replies.