WordPress.org

Ready to get started?Download WordPress

Forums

WP_Query issue/question? (4 posts)

  1. brian914
    Member
    Posted 3 years ago #

    I am trying to create links to only pages found in section 11, but seem to not be able to with what I have so far. I am trying to do it via the following, but I think something is not quite right the way I have the array in the beginning? What am I doing wrong?

    <?php
    	$query = array (
    		'child_of' => 11,
    		 'sort_column' => 'post_title',
    	   	 'post_type' => 'page'
    	);
    
    	$queryObject = new WP_Query($query);
    
    	if ($queryObject->have_posts()) {
    		while ($queryObject->have_posts()) {
    			$queryObject->the_post();
    			the_title();
    		}
    	}
    
    	wp_reset_query();
    ?>

    Thank you very much for any help with this!!!

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    what is the code doing?

    obvioulsly, there is no link html code in the above, so far.

    is it showing the titles of the child pages of page 11?

    link to your site?

  3. brian914
    Member
    Posted 3 years ago #

    I am trying to generate links. So where it now says the_title(), it will later generate li tags, like so:

    while ($queryObject->have_posts()) {
    	$queryObject->the_post();
    	echo '<li><a href="'; the_permalink(); echo '">'; the_title(); echo '</a></li>';
    }

    But for simplicity, I took that out. I was thinking keeping the post simple might make it easier to grasp. Sorry if I wasn't clear, I guess it did the opposite.

    Yes, I would like to show all the subpages of page 11. This is for a sub navigation only on pages of section 11.

    Thanks a lot!

  4. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    http://codex.wordpress.org/Function_Reference/WP_Query#Post_.26_Page_Parameters

    post_parent (int) - use page id. Return just the child Pages.

    try to use the above parameter instead of 'child_of'

    withour checking, i went with the idea that 'child_of' should work ( as it does in get_pages() ), however, it does not seem to be a (valid) parameter of wp_query()

Topic Closed

This topic has been closed to new replies.

About this Topic