Custom query based on post id
-
Im trying to running a custom query and then based on the post id returned in the loop, run a subquery, however I cant seem to find the variable to do the “if” statement on.
As follows:
<?php $querystr = " SELECT wposts.* FROM $wpdb->posts wposts WHERE wposts.post_status = 'publish' AND wposts.post_type = 'page' AND wposts.post_date < NOW() and wposts.id <> 117 ORDER BY wposts.post_title ASC "; $pageposts = $wpdb->get_results($querystr, OBJECT); ?> <?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> ////// THIS is the code I cant seem to figure out, the variable $post.id isnt valid, what should it be ////////////////////// <?php if ($post.id == '5') { echo "You are in Page 5"; } ?> </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 endif; ?>
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Custom query based on post id’ is closed to new replies.