Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type called "Newsitems" that I have registered two custom taxonomies for: "newsitem types" and "news item tags"

I want these two taxonomies' terms to appear almost like the typical post meta info would for categories and tags, but at the client's request they need to function separately than the default post meta.

Despite almost 15 hours of working on this, I still can't get them to render.

Notes:

  • On the single post page, I do get the "newsitem type" ID number, but have been unable to output the actual tax term name.
  • I realize you'll see some Genesis related code, as I'm working with Genesis and used the Genesis Custom Meta Box template to build this. However, my problem (I hope) has a lot less to do with Genesis functionality and moreso regular WordPress behavior. I don't feel this is a case for the Genesis support forums.
  • I'm not a noob, but clearly I don't understand the WordPress loop as well as I should.

My code for the archive page:

function custom_do_loop() {

// Intro Text (from page content)
echo '<div class="page hentry entry">';
echo '<h1 class="entry-title">'. get_the_title() .'</h1>';
echo '<div class="entry-content">' . get_the_content() ;

$args = array(
    'post_type' => 'newsitem', // enter your custom post type
    'orderby' => 'date',
    'order' => 'DESC',
    'posts_per_page'=> '12',  // overrides posts per page in theme settings
    'paged' => get_query_var( 'paged' ),
);

$terms = get_the_terms( $post->ID , 'newsitem-type' );

$loop = new WP_Query( $args );
if( $loop->have_posts() ):

    while( $loop->have_posts() ): $loop->the_post(); global $post;

    echo '<div class="newsitem-listing wrap">';
        echo '<h3><a href="' . genesis_get_custom_field( '_cmb_newsitem_url' ) . '" title="'. get_the_title() . '">' . get_the_title() . '</a></h3>';
        echo '<div class="newsitem-subtitle">' . genesis_get_custom_field( '_cmb_newsitem_subtitle' ) . '</div>'; //retrieve custom field
        echo '<div class="newsitem-source">' . genesis_get_custom_field( '_cmb_newsitem_source' ) . '</div>'; //retrieve custom field
        echo '<div class="newsitem-type">' . $terms->name . '</div>'; //retrieve custom field
        echo '<div class="newsitem-author">' . genesis_get_custom_field( '_cmb_newsitem_author' ) . '</div>'; //retrieve custom field
        echo '<div class="newsitem-pubdate">' . genesis_get_custom_field( '_cmb_newsitem_pub_date' ) . '</div>'; //retrieve custom field
        echo '<div class="synopsis">' . get_the_content() . '</div>';   
    echo '</div>';

    endwhile; 

    genesis_posts_nav();    

endif;

wp_reset_query();

// Outro Text (hard coded)
echo '</div><!-- end .entry-content -->';
echo '</div><!-- end .page .hentry .entry -->';

}

My code for the single posts:

add_action('genesis_before_post_content', 'envision_newsitem_meta');
 function envision_newsitem_meta() {
 global $wp_query;

 $postid = $wp_query->post->ID;
 $subtitle = get_post_meta($postid, '_cmb_newsitem_subtitle' , true);
 $source = get_post_meta($postid, '_cmb_newsitem_source' , true);
 $cattypes = get_post_meta($postid, '_cmb_newsitem_cat_type' , true);
 $author = get_post_meta($postid, '_cmb_newsitem_author' , true);
 $date = get_post_meta($postid, '_cmb_newsitem_pub_date' , true);
 $url = get_post_meta($postid, '_cmb_newsitem_url' , true);
 $tag = get_post_meta($posid, 'post_tag' , true);

 $cattypeString = implode (',' , $cattypes);

 echo '<div class="newsitem-meta"><strong>Subtitle:</strong> ' . $subtitle . '</div>' .       '<div class="newsitem-meta"><strong>Source:</strong> ' . $source . '</div>' . '<div   class="newsitem-meta"><strong>Author:</strong> ' . $author . '</div>' . '<div class="newsitem-meta"><strong>Article Type:</strong> ' . $cattypeString . '</div>' . '<div class="newsitem-meta"><strong>Date Published:</strong> ' . $date . '</div>' . '<div class="newsitem-meta"><strong>URL:</strong> <a href="' . $url . '" target="_blank">' . $url . '</a></div>';

 wp_reset_query();
 }
share|improve this question
1  
I see you are retrieving terms into $terms but don't see you using it for anything. Which part of your code you expect to actually output term information? –  Rarst May 7 '13 at 20:23
    
On the Archives page? Yes, an error in my code -- when I echo $terms by itself, the page breaks. –  electricbrickco May 7 '13 at 20:42
add comment

1 Answer

up vote 2 down vote accepted

get_the_terms() you are using is returning array of items, which cannot be simply echoed to page.

You should try using higher level get_the_term_list() function, which returns string of concatenated results and can be echoed.

share|improve this answer
    
Thanks, Rarst. I know I tried that at some point, but I don't know what I was doing incorrectly. Since I'm using echo, I guess there's no way for me to control when a field is echo conditionally upon its existence, is there? –  electricbrickco May 7 '13 at 21:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.