Support » Fixing WordPress » how to use wp_query

  • Hi,

    I’ve been using a script to query child pages for my portfolio, I’ve been reading a bit and I think I’ve been using something complex while it can be done easier.

    This is the code I’ve been using:

    <?php $this_page_id=$wp_query->post->ID; ?>
    			<?php query_posts(array('showposts' => 12, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_parent' => '9', 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
                    <?php if ( get_post_meta($post->ID, "post-img", true) ) { ?>
                    <?php } else { ?>
    			<!-- DIV's, headers and paragraphs go here -->
                    <?php } ?>
    			<?php } ?>

    Now i’ve been testing this one below and it seems to work just fine:

    <?php query_posts(array('showposts' => 20, 'orderby' => 'menu_order', 'order' => 'ASC', 'post_parent' => 9, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
        <!-- DIV's, headers and paragraphs go here -->
    <?php } ?>

    To be honest I’ve been using the first one since I got into WordPress and wasn’t sure what it did exactly, so if anyone can tell me the difference between the two, and if it’s safe to use the 2nd one.


  • The topic ‘how to use wp_query’ is closed to new replies.