Title: Codex query
Last modified: August 20, 2016

---

# Codex query

 *  Resolved [gavdo](https://wordpress.org/support/users/gavdo/)
 * (@gavdo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/)
 * Hi Newby here
    please advise me if i am posting in wrong section of forum
 * QUESTION:
    Can any one tell how to get the template query below to display articles
   from selected categories only?
 * _[code moderated as per [forum rules ](http://codex.wordpress.org/Forum_Welcome)-
   please use the [pastebin](http://pastebin.com/)
    also, please use the 'code' 
   button to mark any small amounts of code posted directly]

Viewing 8 replies - 1 through 8 (of 8 total)

 *  Thread Starter [gavdo](https://wordpress.org/support/users/gavdo/)
 * (@gavdo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112213)
 * OK I have not used pastebin before. I have the embed codes but how do i get it
   to display here in the forum?
 *  Thread Starter [gavdo](https://wordpress.org/support/users/gavdo/)
 * (@gavdo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112215)
 * [pastebin URL](http://pastebin.com/embed.php?i=EKybHfxN)for full code.
 * small snippet below
 *     ```
       <?php $loop = new WP_Query(array( 'post_type' => 'post', 'orderby' => 'post_date', 'order' => 'DESC', 'posts_per_page' => 15)); ?>
   
       <?php if ($loop->have_posts()): ?>
   
       <?php while ($loop->have_posts()): $loop->the_post(); $posts_counter++; ?><?php
       global $more; $more = 0;
       ?>
       ```
   
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112226)
 * try:
 * `<?php $loop = new WP_Query(array( 'post_type' => 'post', 'orderby' => 'post_date','
   order' => 'DESC', 'posts_per_page' => 15, 'category__in' => array(3,9,23,125));?
   >`
 * [http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters](http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters)
 *  Thread Starter [gavdo](https://wordpress.org/support/users/gavdo/)
 * (@gavdo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112232)
 * Thanks for that. I have tried it but to no avail.
    If you have anymore suggestions
   I would love to try them. Got to go for a while but will check back in 3hrs or
   so.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112252)
 * what is happening if you add the changes?
    – nothing different? – all posts? –
   no posts?
 * are you sure that the page you are looking at is done with the template that 
   you edited?
 * [http://codex.wordpress.org/Template_Hierarchy](http://codex.wordpress.org/Template_Hierarchy)
 * link to your site, to the page where you want to restrict the posts?
 *  Thread Starter [gavdo](https://wordpress.org/support/users/gavdo/)
 * (@gavdo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112364)
 * Hi alchymyth
    When i implimented the change I get a syntex error blank page display
   Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ‘)’
   in /home/phat/public_html/wp-content/themes/theme1122/page_home.php on line 30.
   30 is the modified line It is definately the right template as i have been changing
   various elements on it. The site is [http://www.cre8ivdesign.co.uk](http://www.cre8ivdesign.co.uk)
   and the template operates directly on the front page controling the image grid.
 *  Thread Starter [gavdo](https://wordpress.org/support/users/gavdo/)
 * (@gavdo)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112385)
 * Problem sorted. The original coding was done using $ commands so i removed all
   of these and substituted them for the standard wordpress coding `<?php query_posts('
   cat=4&showposts=15&paged='.$paged); ?><ul class="latest-posts"><?php if (have_posts()):
   while (have_posts()) : the_post(); ?>`
    thank you for your assistance alachymyth
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112404)
 * well done 😉
 * just for your information:
    the parse error was my mistake – i forgot to close
   a bracket in my suggested code changes 🙁 (there should have been three closing
   brackets)

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Codex query’ is closed to new replies.

 * 8 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [14 years, 12 months ago](https://wordpress.org/support/topic/codex-query/#post-2112404)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
