Forums

[resolved] query only parents, without child pages (5 posts)

  1. dwnmedia
    Member
    Posted 1 year ago #

    Hi,

    I want to select (whith query_posts or WP_query) all my main pages without their children. I searched the codex but I was not able to find anything about it.

    Anyone ?

    Regards,

    Jeremy

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

  3. dwnmedia
    Member
    Posted 1 year ago #

    My purpose is to select pages to use them in the loop, can you do that with the function you linked me ?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    In that case, see http://codex.wordpress.org/Function_Reference/WP_Query. Or combine get_pages with a simply foreach type loop.

  5. dwnmedia
    Member
    Posted 1 year ago #

    I solved my problem. I simply used a condition :

    <?php
    query_posts( 'post_type=page' ); // select all the pages
    if (have_posts() ) :
    while (have_posts() ) : the_post();
    if ( ! $post->post_parent ) : // filter the pages without parent
    ?>
    
    <!-- THE LOOP -->

Topic Closed

This topic has been closed to new replies.

About this Topic