Title: Simone's Replies | WordPress.org

---

# Simone

  [  ](https://wordpress.org/support/users/webdesignsimone/)

 *   [Profile](https://wordpress.org/support/users/webdesignsimone/)
 *   [Topics Started](https://wordpress.org/support/users/webdesignsimone/topics/)
 *   [Replies Created](https://wordpress.org/support/users/webdesignsimone/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/webdesignsimone/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/webdesignsimone/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/webdesignsimone/engagements/)
 *   [Favorites](https://wordpress.org/support/users/webdesignsimone/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Custom Post Type Permalinks] Primary category on custom post types](https://wordpress.org/support/topic/primary-category-on-custom-post-types/)
 *  [Simone](https://wordpress.org/support/users/webdesignsimone/)
 * (@webdesignsimone)
 * [5 years, 4 months ago](https://wordpress.org/support/topic/primary-category-on-custom-post-types/#post-14042272)
 * 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 1 replies (of 1 total)