Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Easy wp_get_post_terms problem WordPress

  • SOLVED

I am using custom post type: tattoo

Each post has a single term in the custom taxonomy: styles

I want to redirect single-tattoo.php to the archive for the term

This code outputs the term in a link

$terms = wp_get_post_terms( $post->ID, 'series');
foreach($terms as $term) {
echo "More from this Series: <a href='" . get_term_link($term) . "' title='" . $term->name . "'>" . $term->name . "</a>";
}


I want to put it into:

header("location: link_to_term");

Answers (2)

2015-04-19

Liam Bailey answers:

To convert your code:

$terms = wp_get_post_terms( $post->ID, 'series');

foreach($terms as $term) {

echo "More from this Series: <a href='" . get_term_link($term) . "' title='" . $term->name . "'>" . $term->name . "</a>";

}


into a header location redirect you would do:

$term = reset(wp_get_post_terms( $post->ID, 'series'));
header("Location: " . get_term_link($term));


Austin comments:

That works, thanks!

2015-04-19

Hariprasad Vijayan answers:

Hello,

Not sure where you are trying to do it? May be you can try like this.
global $wp_query;
$wpobject = $wp_query->queried_object;
$term_link = get_term_link($wpobject->term_id);
header("location: ".$term_link);