Title: WP_Query
Last modified: August 30, 2016

---

# WP_Query

 *  Resolved [fjoesne](https://wordpress.org/support/users/fjoesne/)
 * (@fjoesne)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/wp_query-13/)
 * 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](https://wordpress.org/support/users/fjoesne/)
 * (@fjoesne)
 * [10 years, 10 months ago](https://wordpress.org/support/topic/wp_query-13/#post-6442177)
 * 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.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [tags](https://wordpress.org/support/topic-tag/tags/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [fjoesne](https://wordpress.org/support/users/fjoesne/)
 * Last activity: [10 years, 10 months ago](https://wordpress.org/support/topic/wp_query-13/#post-6442177)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
