1

I have a custom Page Template, and this is the code that I am trying to manipulate to change depending on a custom meta value that I write for specific Pages.

$terms = get_the_terms($post->id, 'custom-taxonomy' );

On the Page CPT, I have a custom meta field "Taxonomy Name", and the custom meta value is "Custom Taxonomy"

What I am trying to do with the code above is:

$terms = get_the_terms($post->id, get_post_meta($post->ID,'metafield-taxonomy-name',TRUE) );

Obviously (through actually trying it ;)), that snippet doesn't work since the meta value is not passing through in quotes.

Is there a way I can achieve this, so that 'get_the_terms' can be changed dynamically depending on the meta value that I give it?

Thanks!

Roc.

1 Answer 1

1

Seemed have found a solution via customizing a code snippet from here: http://wordpress.org/support/topic/get_the_terms-using-array-of-taxonomies

$taxonomy = get_the_terms($post->id, get_post_meta($post->ID,'metafield-taxonomy-name',TRUE) );

$terms = get_the_terms($post->id, $taxonomy );
  • $taxonomy must be placed outside of post loop.

Thanks!

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.