Leave a Reply

1 comment

  1. 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" />';
        }
    }