Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter H Ford

    (@bastiensabatier)

    thanks everyone i made it work ??

    Thread Starter H Ford

    (@bastiensabatier)

    anyone ?

    Thread Starter H Ford

    (@bastiensabatier)

    Finally i came up with this :

    function multiple_taxonomy_post_link($CPT_url = '')
    {
      // check permalink structure for the required construct; /%category%/%postname%/
      if (strrpos(get_option('permalink_structure'), '%category%/%postname%') !== false)
      {
        // get the current post
        global $post, $wp_query;
    
        // prepare variables for use below
        $post_id = $term_id = 0;
        $new_CPT_url = ''; 
    
        // for taxonomies
        if (is_tax())
        {
          // remember current category and post
          $term_obj = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
          $term_id = $term_obj->term_id;
          $post_id = $post->ID;
    
          // add the post slug to the current url
          $new_CPT_url = $_SERVER['REQUEST_URI'] . $post->post_name;
        }
    
        else if (is_singular('projects'))
        {
          // last part in the 'category_name' should be the slug for the current category
          $term_object = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
    
          // remember current category and post
          $post_id = $wp_query->post->ID;
          if ($term_object) $term_id = $term_object->term_id;
    
          // replace the slug of the post being viewed by the slug of $post
          $new_CPT_url = $_SERVER['REQUEST_URI'].$post->post_name;
        } 
    
        if ($post_id > 0 && $term_id > 0 && !empty($new_CPT_url))
        {
        	$current_tax = get_query_var( 'taxonomy' );
        	$terms = get_the_terms( $post->ID, $current_tax );
          // make sure categories match!
          foreach($terms as $term)
          {
            if ($term->term_id == $term_id)
            {
              $CPT_url = $new_CPT_url;
              break;
            }
          }
        }
    
      }   
    
      // always return an url!
      return $CPT_url;
    }
    add_filter('post_type_link', 'multiple_taxonomy_post_link');

    Different permalinks are pointing well to the same single post (no 404) but WP keeps rewriting at least ‘my-site/projects/post_name’. Where may i have to look to force WP to keep both url ?
    cheers

    Thread Starter H Ford

    (@bastiensabatier)

    I may transfer all my taxonomies as categories and it will work but I’ll come with a huge amount of categories and by the way, these taxonomies were specific to a custom post type… so now i would have the whole categories for both (posts and custom post types) which would be confusing, no ?
    please any help or advice ?

Viewing 4 replies - 1 through 4 (of 4 total)