QuestionsDisplaying Posts Using a Custom Select Query WordPress
mmWebetutorial Staff asked 6 months ago
$querystring = "
    SELECT $wpdb->posts.* 
    FROM $wpdb->posts, $wpdb->postmeta
    WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id 
    AND $wpdb->postmeta.meta_key = 'tag' 
    AND $wpdb->postmeta.meta_value = 'email' 
    AND $wpdb->posts.post_status = 'publish' 
    AND $wpdb->posts.post_type = 'post'
    AND $wpdb->posts.post_date < NOW()
    ORDER BY $wpdb->posts.post_date DESC

 $Cmposts = $wpdb->get_results($querystring, OBJECT);

<?php if ($Cmposts): ?> 
<?php global $post; ?> 
<?php foreach ($Cmposts 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_attribute(); ?>"> <?php the_title(); ?></a></h2> 
<small><?php the_time('F jS, Y') ?> </small>
 <div class="entry"> 
<?php the_content('Read More »'); ?> 
<p class="metadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit', '', ' | '); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?></p>
<?php endforeach; ?>
 <?php else : ?> 
<h2 class="center">No Result Found</h2>
 <p class="center">Sorry, but you are looking that isn't here.</p>
 <?php endif; ?>

The all of thing you can use in custom template with your custom select query.
Your Answer
Enter email and password to comment or answer
Not the answer you are looking for? Browse other questions tagged or ask your own question.