I have created Custom post type 'references' and two taxonomies under this
e.g
"Custom Taxonomy A" have Categories "Cat-a1" , "Cat-a2"....
"Custom Taxonomy B" have Categories "Cat-b1" , "Cat-b2"....
Each post or reference have assigned one category from Taxonomy A and one from Taxonomy B. I have a template for displaying posts from above Custom post type with respect to Custom Taxonomy A in a loop e.g
Title "Cat-a1"
ALL posts assigned to this category
Title "Cat-a2"
ALL posts assigned to this category
What i am trying is assign a related Category name from Custom Taxonomy B as id of each title
e.g
<div id="Catb1" ><h1>"Cata1"</h1>
ALL posts assigned to this category </div>
<div id="Catb2" ><h1>"Cata2"</h1>
ALL posts assigned to this category </div>
<div id="Catb3" ><h1>"Cata3"</h1>
ALL posts assigned to this category </div>
Here is my Template
<?php
$args=array(
'post_type' => 'references',
'child_of' => 0,
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'references-company',
'pad_counts' => false
);
$categories=get_categories($args);
foreach ( $categories as $category ) {
if ( $category->parent > 0 ) {
continue;
}
$querystr = "SELECT $wpdb->posts.*
FROM $wpdb->posts, $wpdb->term_relationships, $wpdb->terms
WHERE term_id = (" . $category->cat_ID . ")
AND term_taxonomy_id = (" . $category->term_taxonomy_id . ")
AND ID = object_id
AND post_type = 'references'
AND post_status = 'publish'
ORDER BY post_date ASC";
$posts = $wpdb->get_results($querystr, OBJECT);
echo '<div class="content_item" id="';
$term_list = wp_get_post_terms($post->ID, 'references-industry', array("fields" => "names"));
echo $term_list[0];
echo '"><div class="border-r"><div class="quotesimg"><h1 class="termtitle headingopen" style="cursor: pointer;">' . $category->name . '(' . $category->category_count . ')</h1></div></div>';
echo '<div class="references-inner textContent expander">';
foreach ( $posts as $post ) {
setup_postdata($post);
echo '<div class="floatleft twocol-one">';
the_content();
the_excerpt();
echo '<div class="social-linkedin">';
$values = get_post_custom_values("linkedin");
if ( is_array($values) ) {
echo '<a target="_blank" href="';
echo the_field( "linkedin" );
echo '"><img src="';
echo get_template_directory_uri();
echo '/images/ico_social_4.jpg" /></a>';
} else {
echo ' ';
}
echo '</div>';
echo '</div>';
echo '<div class="thumbnail-r fourcol-one last">';
the_post_thumbnail('full');
echo '</div>';
}
echo '</div>';
echo '<div class="moreopen"><p class="more">Mere</p></div>';
echo '</div>';
}
?>
how i can get term/cat names from custom taxonomy B specific to post to use them as ID in div. I have tried in above template but its seems not getting them correctly.
I used this for getting term name assigned to post from Taxonomy B
echo '<div class="content_item" id="'; $term_list = wp_get_post_terms($post->ID, 'references-industry', array("fields" => "names")); echo $term_list[0]; echo '">
Thanks