Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tags and category support #36

Open
andiwand opened this issue Feb 25, 2016 · 5 comments
Open

tags and category support #36

andiwand opened this issue Feb 25, 2016 · 5 comments

Comments

@andiwand
Copy link

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

@DanHawk87
Copy link

+1

1 similar comment
@StefanoVuerich
Copy link

+1

@grappler
Copy link

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

@mikeg-de
Copy link

mikeg-de commented Aug 6, 2017

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;
});

@rgarofalo
Copy link

rgarofalo commented Jul 6, 2022

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%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants