1

I would like to dynamically import different template parts (hardcoded sidebars or navigations) into my layout based on a taxonomy assigned to the post. For instance, this "standard" code works as intended:

<?php get_template_part( 'nav', 'term' ); ?>

and is outputting the (previously hardcoded) file "nav-term.php" where I want it to be. My question: How can I dynamically pick the term of that custom taxonomy assigned to my post and output it as a value of my function? Something like so: "( 'nav', 'dynamically_picked_term' )".

N.b. I'm selecting taxonomy terms by ACF plugin. Also the ACF API could be used.

Thank you in advance for any advice!

1
  • Hello @kaiser. The question was about how to combine 2 wp core functions, custom fields & get_template_part. The use of ACF was an additional info. Edited question to make it better wp related. Thank you. Commented Dec 20, 2014 at 12:33

1 Answer 1

0

You should be able to get at the terms in your custom taxonomy using this function: http://codex.wordpress.org/Function_Reference/wp_get_post_terms

2
  • Thank you @Dan. I tried that one but I couldn't figure out how to use the function. How would you implement it? Commented Dec 20, 2014 at 12:30
  • You'd need to pass your post id and your custom taxonomy. print_r() the results and see what you get.
    – Dan
    Commented Dec 20, 2014 at 12:55

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.