Reputation: 35
I've used the method on the following page to create a Taxonomy named Location.
How can I get the data from the field named Location and return its value. Please help! Thanks
Upvotes: 3
Views: 1693
Reputation: 3614
As per tutorial given in URL above consider register taxonomy name 'location' for media section.Below code will help to fetch data from field location
$tax_terms = get_terms('location', array('hide_empty' => false));
foreach($tax_terms as $term)
{
$termcat = $term->term_id;
$term->name;
$post = get_posts(array(
'post_type' => 'attachment',
'tax_query' => array(
array(
'taxonomy' => 'location',
'field' => 'term_id',
'terms' => $termcat)
))
);
foreach ($post as $mypost)
{
echo $mypost->post_title . '<br/>';
echo $mypost->post_content . '<br/>';
echo $mypost->ID . '<br/><br/>';
echo $mypost->ID . '<img src="'.$mypost->guid.'" width="150" height="150" />';
}
}
Upvotes: 3