Title: Pulling posts using php
Last modified: August 19, 2016

---

# Pulling posts using php

 *  [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/)
 * Hi,
 * I have taken over a wordpress based site which was set up by a web developer (
   who is no longer available to help me)
 * Basically he has PHP code on the front page (a custom template) and this code
   on the page is pulling the post titles etc to show recent activity.
 * The code is:
 * <?php query_posts(‘category_name=press&showposts=10&offset=1’); ?>
 * See where it says “press” it was pulling the posts labeled as “press” – Now I
   am being asked to make it a mix or “press” and “blog”
 * Can anyone tell me how to alter that line so it pulls both? I tried puting in
   a comma after press and then adding blog, but it broke everything. I am a bit
   clueless with PHP after a certain level. Any help would REALLY! help me out.
 * Thanks!

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

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665236)
 * [http://codex.wordpress.org/Function_Reference/query_posts](http://codex.wordpress.org/Function_Reference/query_posts)
 *  Thread Starter [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665243)
 * went to that, I only see this:
 * query_posts(‘category_name=Staff Home’);
 * It doesn’t show me how to grab multiple categories by name? I am really sorry
   If I sound like a total idiot, I am more comfortable with front end design and
   back end PHP stuff tends to easily confuse me.
 * I even tried putting just a space between the words and it broke the thing, again
   a comma doesn’t do it, any more advice?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665301)
 * You need to use category ids if you want to pull from multiple categories. From
   the page I linked to:
 * > Multiple Category Handling
   > Display posts that are in multiple categories. This shows posts that are in
   > both categories 2 and 6:
   > query_posts(array(‘category__and’ => array(2,6)));
 *  Thread Starter [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665313)
 * How do I find out the numbers associated with my categories?
 * When in admin mode when I hover over “pages” I see the numbers associated with
   the pages at the end of the URL, however, the part i need to pull from is in 
   the “posts” section and it doesn’t give you a simple number that is associated
   with the post category.
 * I hope this makes sense, if I can find that out then I can put your advice into
   practice and see if it works for me….
 *  Thread Starter [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665318)
 * sorry, figured out the categories part, got those numbers, will now try out your
   code. will let you know what happened
 *  Thread Starter [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665340)
 * OK, sadly for me that made everything break, as I mentioned before I am not exactly
   a programmer although I am expected to get these things fixed.
 * Below is the entire code chunk for what I am trying to do, just incase this sheds
   more light on a potential problem or makes it easier to see what I am doing wrong
 * _[Code moderated. Please post code snippets between backticks or use a [pastebin](http://wordpress.pastebin.com)
   for larger blocks of code]_
 * The top part:
    **<?php query_posts(‘category_name=blog&showposts=1’); ?>**
 * Shows the most recent post, it shows the excerpt from the page with the date 
   etc.
 * The next part:
    **<?php query_posts(‘category_name=press&showposts=10&offset=
   0’); ?>**
 * I need to keep that showposts=10 part to show the last 10 posts…. could be why
   it all broke?
 * This is where I tried to change it to the other code with the ID’s – Just for
   the record my ID’s are blog=7 and press=3
 * Can you let me know if this even makes even the most remote bit of sense?
 *  Thread Starter [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665485)
 * Ok, this ALMOST did exactly what I wanted it to do….
 * <?php query_posts(array(‘category__and&showposts=10&offset=0’ => array(3,7)));?
   >
 * The feed did show a mix of the 2 categories, BUT! – it didn’t show any more than
   the most recent and the next one, thr part where I have it saying showposts=10
   didnt seem to register. Any ideas?
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665495)
 * `<?php query_posts('category__and' => array(3,7) . '&posts_per_page=10'); ?>`
 *  Thread Starter [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * (@stirlingcreative)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665496)
 * thanks man, but that made the whole page vanish, I reverted though so its cool,
 * I know I am so close yet so far from getting this to work…..

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

The topic ‘Pulling posts using php’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 2 participants
 * Last reply from: [stirlingcreative](https://wordpress.org/support/users/stirlingcreative/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/pulling-posts-using-php/#post-1665496)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
