• Resolved leliathomas

    (@leliathomas)


    I’m using a custom post that’s functioning just fine in my template, but I can’t seem to get the_tags to play nicely with it. Here is my code:

    <?php $loop = new WP_Query( array( 'post_type' => 'portfolio-artwork', 'posts_per_page' => 5 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <div class="thumbnail"><a>" title="<?php the_title(); ?>"><?php echo strip_tags( get_post_meta($post->ID, 'Medium-Sized Thumbnail', true), '<img>' ); ?></a></div>
       <h3 class="worktitle"><a>" title="<?php the_title(); ?>"><?php the_title(); ?></a>, created in <?php the_time('F Y'); ?></h3>
       <p class="portfolio-page-tagged">Tagged under  <?php the_tags('', ', '); ?></p>
       <div class="hrmedium"></div>
    <?php endwhile; ?>

    Everything is coming out as it should, but nothing is coming up for the_tags. I don’t have any rag-related plugins installed, either. Any ideas?

    Cheers,
    Lelia

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Put this behind the WP_Query and see if it works:
    <?php $wp_query->in_the_loop = true; ?>
    Seems to be that the WP_Query is not recognized as a loop (which the_tags() tests for).

    Thread Starter leliathomas

    (@leliathomas)

    Didn’t seem to work, unless I’m putting that in the wrong place (which is possible considering I’m more of a designer!).

    <?php $wp_query->in_the_loop = true; ?>
    <?php $loop = new WP_Query( array( 'post_type' => 'portfolio-artwork', 'posts_per_page' => 5 ) ); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
       <div class="thumbnail"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php echo (get_post_meta($post->ID, 'Medium-Sized Thumbnail', true)); ?></a></div>
       <h3 class="worktitle"><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>, created in <?php the_time('F Y'); ?></h3>
       <p class="portfolio-page-tagged">Tagged under  <?php the_tags('', ', '); ?></p>
       <div class="hrmedium"></div>
    <?php endwhile; ?>

    Same results…just nothing coming up for the_tags.

    Thanks,
    Lelia

    Thread Starter leliathomas

    (@leliathomas)

    Finally figured it out, thanks to this blog entry by Justin Tadlock! For any passersby, here’s the code that will work to pull custom taxonomies for their custom post types:

    <?php echo get_the_term_list( $post->ID, 'CUSTOM TAXONOMY NAME HERE', 'TEXT BEFORE', 'SEPARATOR', 'TEXT AFTER' ); ?>

    Cheers,
    Lelia

    Moderator keesiemeijer

    (@keesiemeijer)

    Glad you found a solution.
    You put the “in_the_loop = true” in the wrong place. Here is where you put it:

    <?php $loop = new WP_Query( array( 'post_type' => 'portfolio-artwork', 'posts_per_page' => 5 ) ); ?>
    <?php $wp_query->in_the_loop = true; ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom Post Types and the_tags’ is closed to new replies.