terriwun Posted September 15, 2015 Share Posted September 15, 2015 I have a custom field where the user (wordpress admin) will check off the term name they want associated with a blog post. I currently get the term id returned. is there a way to get the slug as an end result? <?php $term = get_field('acf_term'); if( !empty($term) ): ?> <div> <asp_info> <strong> <?php $field_object = get_field_object( 'acf_term', $post->ID ); echo $field_object['label'];?></strong> <?php the_field('acf_term'); ?> </div> <?php endif; ?> this returns : Term slug: 865 I want it to return : Term slug: interest-tag-name Thanks for any help. Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 15, 2015 Share Posted September 15, 2015 That depends on the advanced custom fields plugin, may have to add that function in the plugin. Quote Link to comment Share on other sites More sharing options...
terriwun Posted September 15, 2015 Author Share Posted September 15, 2015 Thanks, the custom field plugin returns the term id, i figured after it returns the id i can then use that to find the term slug? yes? no? Quote Link to comment Share on other sites More sharing options...
maxxd Posted September 15, 2015 Share Posted September 15, 2015 Have you tried get_term_by()? Looks like it may do what you're looking for. Perhaps? Quote Link to comment Share on other sites More sharing options...
terriwun Posted September 15, 2015 Author Share Posted September 15, 2015 thanks maxxd, I tried but i don't think i am writing the code properly. would you be able to show me how i would incorporate it using my code above? Sorry i have totally confused myself :-) Quote Link to comment Share on other sites More sharing options...
hansford Posted September 15, 2015 Share Posted September 15, 2015 http://codex.wordpress.org/Function_Reference/get_term In the Examples section it appears to demonstrate how to get the slug. $term = get_term( $term_id, $taxonomy ); Gives you term slug: e.g.: term-slug-example $slug = $term->slug; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.