Title: &quot;get_posts(array&quot; troubles&#8230;
Last modified: August 19, 2016

---

# "get_posts(array" troubles…

 *  Resolved [relaysignal](https://wordpress.org/support/users/relaysignal/)
 * (@relaysignal)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/)
 * I’m trying to get my Category Template to be able to not only show the posts 
   from that category, but to also show a single post from the ‘featured’ category
   as well. But it’s not just any post from the featured category, it’s the most
   recent post that happens to be in both the featured category and the category
   the page is on. Does that make sense? Here’s my code for the single (Featured
   + Category) post:
 * _[Code moderated as per the [Forum Rules](http://codex.wordpress.org/Forum_Welcome).
   Please use the [pastebin](http://wordpress.pastebin.com/)]_
 * I’m not real great with php, and I keep getting serrors that I’m missing a bracket,
   but I can’t see where. Any help? 🙂

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

 *  Thread Starter [relaysignal](https://wordpress.org/support/users/relaysignal/)
 * (@relaysignal)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930609)
 * Here’s my code: [http://wordpress.pastebin.com/C10RdbPh](http://wordpress.pastebin.com/C10RdbPh)
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930610)
 * try to put all arguments into the array; for instance:
 *     ```
       $news =array(
       'category__and' => array(47,3),
       'posts_per_page' => 1
       );
       $my_query = new WP_Query($news);
       while ($my_query->have_posts()) : $my_query->the_post();
       ```
   
 *  Thread Starter [relaysignal](https://wordpress.org/support/users/relaysignal/)
 * (@relaysignal)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930618)
 * I fixed the code but I still get a _“Parse error: syntax error, unexpected ‘}’
   in …/wp-content/themes/travelertheme/category.php on line 34”_ error.
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930620)
 * Can we have the full code on the category template?
 *  Thread Starter [relaysignal](https://wordpress.org/support/users/relaysignal/)
 * (@relaysignal)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930623)
 * Here it is:
 * [http://wordpress.pastebin.com/A62dJ0ML](http://wordpress.pastebin.com/A62dJ0ML)
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930624)
 * Try it with this: [http://wordpress.pastebin.com/nR1sh4VG](http://wordpress.pastebin.com/nR1sh4VG)
 * I think it needs an `endif;` before the ‘}’ and thats why it doesn’t work
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930627)
 * as far as i know, you can’t interrupt a ‘while’-loop with a closing bracket of
   an unrelated conditional statement.
 * the line `while ($my_query->have_posts()) : $my_query->the_post();` is common
   to all queries and need only be inserted once, at the start of the actual loop.
 * all conditional statements to set the arguments and the query should imho be 
   processed before the start of the loop.
 * also inserted a ‘wp_reset_query();’ before the second loop, to bring the query
   back to the original category posts.
 * for instance:
    [http://wordpress.pastebin.com/2u0JUn29](http://wordpress.pastebin.com/2u0JUn29)
 * (untested)
 *  Thread Starter [relaysignal](https://wordpress.org/support/users/relaysignal/)
 * (@relaysignal)
 * [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930662)
 * Thank you very much, everyone! The code Alchymyth wrote works like a charm.

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

The topic ‘"get_posts(array" troubles…’ is closed to new replies.

## Tags

 * [array](https://wordpress.org/support/topic-tag/array/)
 * [categories](https://wordpress.org/support/topic-tag/categories/)
 * [get_posts](https://wordpress.org/support/topic-tag/get_posts/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 8 replies
 * 3 participants
 * Last reply from: [relaysignal](https://wordpress.org/support/users/relaysignal/)
 * Last activity: [15 years, 2 months ago](https://wordpress.org/support/topic/get_postsarray-troubles/#post-1930662)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
