• Lisa Boyd

    (@leaseahb)


    I am working through the Codex page:
    Displaying Posts Using a Custom Select Query

    When I view the page, it is pulling the correct posts, but it is displaying them twice.

    Here’s the query code:

    <?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 = 3
        AND $wpdb->term_taxonomy.taxonomy = 'category'
        AND $wpdb->posts.post_status = 'publish'
        AND $wpdb->postmeta.meta_key = 'Issue'
    	  AND $wpdb->postmeta.meta_value = 1
        ORDER BY $wpdb->postmeta.meta_value ASC
     ";
    
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    
     ?>

    I am using the Revised Loop from the Codex page mentioned above:

    <?php if ($pageposts): ?>
     <?php foreach ($pageposts as $post): ?>
     <?php setup_postdata($post); ?>
    
     <div class="post" id="post-<?php the_ID(); ?>">
     <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
        <?php the_title(); ?></a></h2>
    <!--    <small><?php the_time('F jS, Y') ?>  by <?php the_author() ?> </small> -->
        <div class="entry">
           <?php the_content('Read the rest of this entry ?'); ?>
        </div>
        <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?>
        <?php comments_popup_link('No Comments ?', '1 Comment ?', '% Comments ?'); ?></p>
     </div>
     <?php endforeach; ?>
     <?php else : ?>
        <h2 class="center">Not Found</h2>
        <p class="center">Sorry, but you are looking for something that isn't here.</p>
        <?php include (TEMPLATEPATH . "/searchform.php"); ?>
     <?php endif; ?>

    Do I have something wrong in the query? I did add the meta_value to the query.

    Thanks for any light you can shed on this.
    Lisa B.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Custom Select Query showing 2 of each post’ is closed to new replies.