WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Post Types and the_tags (5 posts)

  1. leliathomas
    Member
    Posted 4 years ago #

    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

  2. keesiemeijer
    moderator
    Posted 4 years ago #

    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).

  3. leliathomas
    Member
    Posted 4 years ago #

    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

  4. leliathomas
    Member
    Posted 4 years ago #

    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

  5. keesiemeijer
    moderator
    Posted 4 years ago #

    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(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic