WordPress.org

Forums

getting Categories assoc with post (5 posts)

  1. glennn
    Member
    Posted 5 years ago #

    i'm using a plugin that uses php a little differently than i'm familiar with (i'm only a novice) - i want to get the categories from the query the plugin uses, like so:

    [code]
    $pbcresults = $wpdb->get_results("SELECT *
    FROM $wpdb->posts, $wpdb->term_relationships,$wpdb->term_taxonomy
    WHERE
    $wpdb->posts.post_status = 'publish'
    AND $wpdb->posts.post_type = 'post'
    AND $wpdb->posts.id = $wpdb->term_relationships.object_id
    and
    $wpdb->term_relationships.term_taxonomy_id=$wpdb->term_taxonomy.term_taxonomy_id
    AND $wpdb->term_taxonomy.term_id =$catid_in
    ORDER BY $wpdb->posts.post_date DESC , $wpdb->posts.post_title ASC
    LIMIT $count");
    
    foreach ( $pbcresults as $pbcresult )
    		{
    	$the_output .= '<h1 class="post-title"><a>ID) . '">' . apply_filters('the_title', $pbcresult->post_title) . '</a></h1>';
    	 $the_output .=  apply_filters('the_content', $pbcresult->post_content);
    
    // need to get the Cats and Tags here...
    
    [/code]

    i could figure out how to get the post_content, but can't get an array from this query - if someone could help me, i'd appreciate it...

    thanks
    gn

  2. MichaelH
    Member
    Posted 5 years ago #

    <?php
    $args=array(
      'cat' => $catid_in,
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content('Read the rest of this entry &raquo;');
        the_category(',');
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    See Template_Tags/the_category or Template_Tags/get_the_category

  3. glennn
    Member
    Posted 5 years ago #

    thanks - not quite sure how incorporate the_category(); into

    $the_output .= '<div class="post-meta"><div class="row">';
    $the_output .=  apply_filters('the_content', $pbcresult->post_content);
    
    $the_output .=   '<em>'. the_category(); . '</em>';
    
    $the_output .= '</div></div>';

    don't know where to place your query - within the $the_output .= ''; ?

  4. MichaelH
    Member
    Posted 5 years ago #

    That code was meant to replace your code and to show another way of retrieving and displaying post, but you'd need to add the necessary div elements.

  5. glennn
    Member
    Posted 5 years ago #

    oh - :o)
    thanks !!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.