Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter christianl86

    (@christianl86)

    I just replaced the file -> frontend/class-permalinks-customizer-form.php:

    // Replace %category% with the respective post category with their parent categories
    		if (strpos( $replace_tag, "%category%" ) !== false ) {
    			$categories = get_the_category( $post_id );
    			$total_cat  = count( $categories );
    			$tid = 1;
    			if ( $total_cat > 0 && is_array( $categories ) ) {
    				$tid = '';
    				foreach ( $categories as $cat ) {
    					if ( $cat->term_id < $tid || empty( $tid ) ) {
    						$tid = $cat->term_id;
    						$pid = '';
    						if ( ! empty( $cat->parent ) ) {
    							$pid = $cat->parent;
    						}
    					}
    				}
    			}
    			$term_category = get_term( $tid );
    			$category      = is_object( $term_category ) ? $term_category->slug : '';
    			if ( ! empty( $pid ) ) {
    				$parent_category = get_term( $pid );
    				$category        = is_object( $parent_category ) ? $parent_category->slug . '/' . $category : '';
    			}
    			$replace_tag = str_replace( '%category%', $category, $replace_tag );
    		}

    TO

    // Replace %category% with the respective post category with their parent categories
    		if (strpos( $replace_tag, "%category%" ) !== false ) {
    			$categories = get_the_category( $post_id );
    			
    			global $wpdb;
    			$query = "SELECT * FROM <code>&quot;.$wpdb->prefix.&quot;postmeta</code> WHERE <code>post_id</code> = ".$post_id." AND <code>meta_key</code> = '_yoast_wpseo_primary_category'";
    			$res = $wpdb->get_results($query);
    			$tid = $res[0]->meta_value;
    
    			$term_category = get_term( $tid );
    			$category      = is_object( $term_category ) ? $term_category->slug : '';
    			if ( ! empty( $pid ) ) {
    				$parent_category = get_term( $pid );
    				$category        = is_object( $parent_category ) ? $parent_category->slug . '/' . $category : '';
    			}
    			$replace_tag = str_replace( '%category%', $category, $replace_tag );
    		}

    And it works, I need to know how to regenerate the url to posts created before install this plugin… “Convert Custom Permalink” isn’t working for me.

Viewing 1 replies (of 1 total)