You’re looking for post__in
& post__not_in
parameters http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters
Both of them are an array of ID’s for the post’s to include or exclude in the results
BTW in your code, you had a semicolon just after your foreach
Related Posts:
- Query posts and display all dates in repeater field in chronological order
- WordPress loop: Display if posts exist
- How to fix pagination for custom loops?
- Remove the Homepage Query
- Is `query_posts` really slower than secondary query?
- Are there any scenarios where the query_posts may be used?
- Transient not working for custom loops
- post__in – Placing content from a foreach loop inside of an array
- post loop causes wp_users and wp_usermeta DB queries for each users
- get_the_foo() in the loop – does it perform another query?
- If No Search Results, Show Posts from Alternate Search Query
- How to Loop within a Loop (Display Children and then Grandchildren)
- Loop posts only excluding first post
- Loop after page content
- A loop with all articles with certain text strings in tags
- Display most viewed post from last 30 days is not working correctly
- Query posts if meta key starts with
- 3 Posts in Loop, Show Stickies First
- How to go about combining dropdowns / filter queries?
- Query reset problem or flawed code to enable custom post type query
- Query last updated posts (posts updated in the last 24 hours)
- Orderby my needs in foreach loop like by title or something?
- Conditional query that displays on Woo product attribute pages
- How do I use AJAX Query in my posts loop?
- woocommerce get_price_html not pulling in correct price
- How to fix pagination for custom loops?
- How can I paginate this?
- How to display posts by vote count and if no value continue with latest posts with no votes?
- How to fix pagination for custom loops?
- Split wordpress loop to multiple layouts
- Problem with displaying HTML content after in_array [closed]
- Making a query to the DB using same parameters of loop
- Output from Meta Box Array
- Include current post into loop
- Array ids post to function have_post
- Can’t access PHP array inside script localization from javascript
- Loop inside query
- Output meta into arrays
- Trying to get property of non-object in shortocde
- How can I access specific posts brought back by query_posts?
- How to create a multidimensional array with multiple loops
- How to get user ID’s from multiple usernames?
- Loop through an array inside a class using foreach [closed]
- get_delete_post_link() inside Loop stubbornly returns nothing
- loop inside the foreach
- Query posts only with actual text content (not including shortcode or images)
- CPT while loop not working
- display post tags on single.php inside loop
- Query post & loop problem.
- Add 2 values to post__not_in
- Loops for cat links not looping for wordpress site
- How do I set the Stewart Search Template to return only published posts in the result
- Trying to get all links in my posts
- Custom Query with Sticky Posts
- Build a Page which shows the Oldest Post with specific Custom Field Value
- Slug is changing when I use WP_Query in a metabox of a post
- How to fix pagination for custom loops?
- Get featured image outside the loop using foreach
- Alternative layout the loop
- Why loop renders only last metabox from array? [closed]
- Show posts by tags excluding current post
- Strange problem with wp_get_attachment_image_src database (db) query count
- Next 10 posts data of currently viewing post in blog page
- How to fix pagination for custom loops?
- Humanmade | Custom meta box class: How to display a repeatable meta box group?
- Can’t print out returned value
- How to fix pagination for custom loops?
- How to fix pagination for custom loops?
- Get query result before posts are displayed?
- Combine Query and Select Database to create directory loop
- Randomly Display One Image From a 10-Image For Loop
- wordpress showing all posts instead of date range
- How can I access ‘key’ and ‘value’ from an array in a for loop?
- Multiple loop with pagination in same page
- How to get files from loop for zip
- Query Loop Block: possible to restrict just child pages?
- Use Base-URL with Query-Loop
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- Adding ‘current_post_item’ class to current post in the loop
- Listing all posts from current category on page
- How to make multiple Column in archive Page?
- Sort Popular Posts by Views for the Last Week
- Adding shortcode closing tag after a loop
- Change front-page layout after x amount of posts ( while in the same loop)
- Filter the loop by categories using checkbox form
- Checking array against author id in loop
- query_posts() vs get_posts() multiple loops [duplicate]
- How do I make a variable available inside partials?
- Display Post Author Link above the loop
- Transient api Caches confused
- Conditional: IF current user has NOT commented on current post (not including post author)
- Loop Problem: Displays same set of post for all categories
- get_users with array as meta_value
- Posts not showing
- Set depth of pages to fetch
- Creating a User-Adjustable chart in WordPress
- How to execute a user loop with shortcode
- using the loop on a page
- Display all posts in a page code for template