wp-polylang-translate-rewrite-slugs icon indicating copy to clipboard operation
wp-polylang-translate-rewrite-slugs copied to clipboard

tags and category support

Open andiwand opened this issue 9 years ago • 5 comments

it would be awesome if tags and categories would be supported as well!

andiwand avatar Feb 25 '16 12:02 andiwand

+1

DanHawk87 avatar Apr 06 '16 07:04 DanHawk87

+1

StefanoVuerich avatar Nov 26 '16 13:11 StefanoVuerich

See the pro version of Polylang Pro, which has this feature.

grappler avatar Nov 26 '16 13:11 grappler

Before adding this plugin I managed to add a sub-category to a custom taxonomies slug but now it outputs %project_cateogry% in the URL. Maybe the following code help kicking off a solution:

// renaming project custom post type
// https://ayanize.com/snippets/how-to-rename-project-post-type-to-anything-or-create-a-new-post-type-with-divi-page-builder-on/
// And add sub-category https://www.elegantthemes.com/forum/viewtopic.php?f=187&t=728022&hilit=portfolio+category&p=4008597#p4008597
function rename_project_cpt() {

register_post_type( 'project',
	array(
	'labels' => array(
	'name'          => __( 'Immobilien', 'divi' ), // change the text portfolio to anything you like
	'singular_name' => __( 'Immobilie', 'divi' ), // change the text portfolio to anything you like
	),
	'has_archive'  => true,
	'hierarchical' => true,
    'menu_icon'    => 'dashicons-building',  // you choose your own dashicon
	'public'       => true,
	
	'rewrite'      => array( 'slug' => 'immobilien/%project_category%', 'with_front' => false ), // change the text portfolio to anything you like
  'supports'     => array(),
         
));
    }
 
add_action( 'init', 'rename_project_cpt' );

function wpa_show_permalinks( $post_link, $post ){
  if ( is_object( $post ) && $post->post_type == 'project' ){
    $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', 'wpa_show_permalinks', 1, 2 );

// Translate Custom taxonomy Slug
// https://github.com/KLicheR/wp-polylang-translate-rewrite-slugs/blob/master/README.md
add_filter('pll_translated_post_type_rewrite_slugs', function($post_type_translated_slugs) {
	// Add translation for "product" post type.
	$post_type_translated_slugs = array(
		'project' => array(
			'en' => array(
				'has_archive' => true,
				'rewrite' => array(
					'slug' => 'estate/%project_category%'
				),
			),
		),
	);
	return $post_type_translated_slugs;
});

mikeg-de avatar Aug 06 '17 11:08 mikeg-de

add_filter( 'post_type_link', 'wpa_show_permalinks', 11, 4 );

the priority must be lower otherwise you cannot correct the url because it still does not contain %project_category%.

rgarofalo avatar Jul 06 '22 18:07 rgarofalo