Support » Fixing WordPress » 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; ?>
                    <?php the_title(); ?>
                	<?php the_content(); ?>
                    <?php the_id(); ?>
    <?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(); ?>
                                <a href="<?php the_permalink(); ?>" title="Go to article">
                                    <?php the_title(); ?>
                                Posted on <?php the_date(); ?> by <?php the_author(); ?>
    <?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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try using get_posts logic for your second query

    That helped me – never tried that and will use it in future. Thanks 🙂

    It still doesn’t work calling page data with any sort of query/loop however.

    The only way I can get it work by using no loop at all just putting the page content onto the page directly using <?php echo $post->post_title; ?> etc.

    This is problematic for <?php echo $post->post_content; ?> as it strips the WYSIWYG paragraph tags but I guess it’ll have to do for now unless anyone has a better solution?

    Can you pull <?php echo $post->post_content; ?> whilst retaining the paragraph tags?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Page Query AND Post Query on the same page’ is closed to new replies.