WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_tags() not working with custom query (5 posts)

  1. anabelle
    Member
    Posted 6 years ago #

    Im using the following custom query to display a random post from a category in the sidebar:

    <?php
    		$querystr = "SELECT * FROM $wpdb->posts
    		LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    		LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    		LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    		WHERE $wpdb->term_taxonomy.term_id = 6 AND $wpdb->term_taxonomy.taxonomy = 'category'
    		AND $wpdb->posts.post_status = 'publish'
    		AND $wpdb->postmeta.meta_key = 'imagen'
    		ORDER BY RAND() LIMIT 1";
    
    		$pageposts = $wpdb->get_results($querystr, OBJECT);
    
    		?>
    
    	<?php if ($pageposts): ?>
    	<?php foreach ($pageposts as $post): ?>
    
    		<?php setup_postdata($post); ?>

    From there on i continue.. with <h2><? the_title();... ?>' as usual, but if i try to use<? the_tags(); ?>` it doesn't display anything, what shoul I do in order to display the tags?

  2. Michael Fields
    Themer
    Posted 6 years ago #

    This worked for me:

    print get_the_term_list( $post->ID, 'post_tag', '<p>', ' ', '</p>' ) ;

    Args: resource_ID, taxonomy, before, seperator, after

  3. anabelle
    Member
    Posted 6 years ago #

    Thank You!!

  4. Michael Fields
    Themer
    Posted 6 years ago #

    your welcome!

  5. soniczen
    Member
    Posted 5 years ago #

    the_tags(); was not working for me with a query like this:

    $somePosts = new WP_Query();

    print get_the_term_list(...); worked out just great. Thank you.

Topic Closed

This topic has been closed to new replies.

About this Topic