• Resolved fjoesne

    (@fjoesne)


    Trying the following:

    $parent = 171;
    $tag = get_the_title();
    $criteria = array(
    	'posts_type' => 'page',
    	'post_status' => 'publish',
    	'orderby' => 'ASC',
    	'post_per_page' => -1,
    	'post_parent' => $parent,
    	'tag' => $tag,
    );
    $pages = new WP_Query($criteria);
    if ( $pages->have_posts() ) {
    	foreach ( $pages as $page ) {
    		$url = get_page_link($page->ID);
    		echo '<a href="'. $url .'">' . $page->post_title . ' Page-title: </a>'.$page->.'<br>';
    	}
    	wp_reset_postdata();
    } else {
    	echo "No match..";
    }

    This returns a bunch of debug:

    Page-title:
    Page-title:
    Page-title:
    Page-title:
    testpage Page-title: testpage
    Page-title:
    Page-title:
    Page-title:

    But i have a testpage2 with the same tag, what am i doing wrong here? and why does it give me a bunch of blanks? I thought the $criteria array would limit only to matching tags. Also the parent specified has only 2 pages, seems like it is running through all pages.

Viewing 1 replies (of 1 total)
  • Thread Starter fjoesne

    (@fjoesne)

    misuse of loop..
    solution:

    $pages = new WP_Query($criteria);
    if ( $pages->have_posts() ) {
    	while ( $pages->have_posts() ) {
    		$pages->the_post();
    			echo '<a href="'.get_page_link().'">'.get_the_title().'</a><br>';
    	}
    	wp_reset_postdata();
    } else {
    	echo "No match..";
    }

Viewing 1 replies (of 1 total)

The topic ‘WP_Query’ is closed to new replies.