Page Query AND Post Query on the same page
-
Hey
I’m trying to get something to output on my posts page but I’m not having any luck (I’ve set my site up primarily as a CMS..the “posts” are articles in categories with custom fields etc.)
What I’m trying to do is call PAGE data with one query and then follow it up calling POSTS later on the page but somehow they interfere with each other.
Here is my query to call page data (title and page content as a CMS)
<?php $my_query = new WP_Query("showposts=1&post_type=page&page_id=27"); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?> <h1> <?php the_title(); ?> </h1> <p> <?php the_content(); ?> </p> <p> <?php the_id(); ?> </p> <?php endwhile; ?>
Later on I’m trying to call “recent articles” (posts) via this loop
<?php query_posts("showposts=5&post_type=post&orderby=date"); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <li> <h4> <a href="<?php the_permalink(); ?>" title="Go to article"> <?php the_title(); ?> </a> </h4> <p> Posted on <?php the_date(); ?> by <?php the_author(); ?> </p> </li> <?php endwhile;?>
The posts return fine but even though I’ve set &page_id=27 in the first page query I still get a return of ID #89 (I assume the last page posted?)
Does anyone have any ideas so I can get them both to call correctly on the same page? I’ve tried them as loops, query posts and WP_queries in every mixture but the page data still doesn’t return as I want it to ??
Thanks a lot.
- The topic ‘Page Query AND Post Query on the same page’ is closed to new replies.