• Resolved tcushing

    (@tcushing)


    I have the following code on a custom page template to retreive particular posts. I can’t seem to figure out what to add to this so that I can also get posts of a particular category. Any help would be appreciated. Thanks.

    <?php
     $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wpostmeta.meta_key = 'sidedate'
        AND wpostmeta.meta_value > NOW()
        ORDER BY wpostmeta.meta_value desc
     ";
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    ?>
    <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post_title); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title();
    ?></a></li>
     <?php endforeach; ?>
    <?php endif; ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tcushing

    (@tcushing)

    Awesome, thanks!

    One more question – can you please direct me to where I can find out how to set the ORDER BY to a post tag for the code below instead of the meta value:

    <?php
    
     $querystr = "
        SELECT wposts.*
        FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
        WHERE wposts.ID = wpostmeta.post_id
        AND wposts.post_status = 'publish'
        AND wposts.post_type = 'post'
        AND wpostmeta.meta_key = 'mathdate'
        AND wpostmeta.meta_value > NOW()
        ORDER BY wpostmeta.meta_value desc
     ";
     $pageposts = $wpdb->get_results($querystr, OBJECT);
    ?>
    <?php if ($pageposts): ?>
      <?php foreach ($pageposts as $post): ?>
        <?php setup_postdata($post_title); ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title();
    ?></a></li>
     <?php endforeach; ?>
    <?php endif; ?>

    You’d have to add JOINs for the taxonomy table(s) then do a ORDERBY one of those fields.

    Thread Starter tcushing

    (@tcushing)

    Thanks! I’ll chip away at it!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get categories’ is closed to new replies.