0

I have registered custom post taxonomy with rewrited name:

register_taxonomy('behold_gallery-albums-subject', 'behold_gallery',array(
    'hierarchical'              => true,
    'labels'                    => $labels,
    'show_ui'                   => true,
    'show_admin_column'         => true,
    'rewrite'                   => array( 'slug' => 'kategorie-galerii', 'with_front' => true ),
    'update_count_callback'     => '_update_post_term_count',
    'query_var'                 => true,
));

so name of my custom taxonomy is 'behold_gallery-albums-subject' but is rewrited to 'kategorie-galerii'.

If I want to get name of this taxonomy, I can use this

$postsTaxonomy = get_sub_field('archive__post-choose-taxonomy'); // ACF
$postsTerm = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) ); 
$postsTerm_id = $postsTerm->term_id;
$PostsTaxName = get_taxonomy($postsTaxonomy)->labels->name;

but how can I get this rewrited name, not the 'original'?

Thanks!

1 Answer 1

0

Do you mean just get the rewritten slug? From the docs it looks like you should be able to do:

$rewrite_name = get_taxonomy($postsTaxonomy)->rewrite['slug']

Or do you mean something else?

7
  • Yes, I need slug. But your code doesn't work and I've tried it before. In this case $rewrite_name = get_taxonomy($postsTaxonomy)->rewrite; print_r($rewrite_name); I see the array content and my slug name. So your code should work - am I right?
    – D_P
    Commented Jun 30, 2020 at 16:00
  • yes, and it sounds like it is working if you see an array, you just need to add the ->slug on the end to get the slug name
    – mozboz
    Commented Jun 30, 2020 at 16:05
  • Of course, I've added '-> slug', but I don't see any rewrited slug name... and that's the issue. So - in array I see it, but with $rewrite_name = get_taxonomy($postsTaxonomy)->rewrite->slug; echo $rewrite_name; I don't.
    – D_P
    Commented Jun 30, 2020 at 16:08
  • can you add to your question what you see when you do print_r($rewrite_name);
    – mozboz
    Commented Jun 30, 2020 at 16:09
  • oh, sorry i just realised, it's an array, not another object. i'll update the answer
    – mozboz
    Commented Jun 30, 2020 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.