You should read the function reference for WP_Query on the WordPress codex. There you have a lot of examples to look at. If you don’t want to loop over the result set using a while, you could get all posts returned by the query with the WP_Query in the property posts.
For example:
1 2 3 4 5 6 7 | $query = new WP_Query( array( 'post_type' => 'page' ) ); $posts = $query->posts; foreach($posts as $post) { // Do your stuff, e.g. // echo $post->post_name; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.