get_posts() is a function for creating multiple loops. It retrieves a list of latest posts or posts matching criteria.

learn more… | top users | synonyms

200
votes
6answers
65k views

When should you use WP_Query vs query_posts() vs get_posts()?

It seems like half the tutorials in the Codex and around the blogosphere use query_posts() and half use WP_Query. What's the deal?
5
votes
2answers
942 views

Differences Between WP_Query() and get_posts() for Querying Posts?

What are the differences between using WP_Query() and get_posts()? Which is better to use in what case and why?
0
votes
0answers
71 views

Combining / Merging two queries?

So I am working on an isotope filtered portfolio page that pulls any attachment tagged with the term "digital-interactive". Each attachment is also linked to a custom post_type called "work". On one ...
0
votes
0answers
37 views

get-posts pull 2 levels of sub pages

The template structure is: a Product index (parent page) b Product category (sub parent page) c Product single (page) They're all Pages, not Posts. 1 On index page, to pull out the page title from ...
0
votes
1answer
65 views

Show recent posts in single-post page

I'm trying to show recent custom posts in single-events.php I can make it work by using get_posts what I don't know how to do is exclude the post that is active so if I'm on 'Event 1' just now using ...
0
votes
3answers
138 views

Get post offset/posts page offset in single post page (outside the loop)

I would like to know how I could get the offset of a custom post or its page, outside the get_posts loop. I developed an external web application which connects to the wordpress blog with JSON API ...
0
votes
1answer
182 views

How to show more post at a given category?

I need to show more post at the category state (with tag_ID=21), for example, I set the number of post show at homepage is 6, but I want 10 post when archive state, is there any way to add a filter in ...
0
votes
0answers
38 views

loop with the last commenter on each post on specific category

Hi i have the following code that lists the posts from specific category and the date, post author, the last comment author, last comment date and the avatar for comment author for each post on the ...
0
votes
1answer
64 views

List all pages including archive

I'm creating a custom options page on my site. One of the options is controlling a box on the homepage and i'm trying to set the link for the item to any page on the site via a select menu. as of now ...
0
votes
1answer
93 views

get_posts and wp_autop (remove filter)

I just transformed my query_posts function in a get_posts function. Here is my old function: <?php // The Query query_posts( 'cat=170&showposts=4' ); remove_filter('the_excerpt', 'wpautop'); ...
0
votes
1answer
62 views

get_posts output always same post

I'm trying to output the last (chronologically) 4 posts having the tag (slug) "pp". <ul> <?php $args = array( 'posts_per_page' => 4, 'taxonomy' => 'tag', 'field' => 'slug', 'terms' ...
0
votes
0answers
594 views

How do I paginate a get_posts() request inside another page loop (Paginating childpages)

The heading says a lot, so I'll repeat it here "How do I paginate a get_posts() request inside another page loop?" I'm using a page to display child-pages and I need to paginate them. Edit: Should I ...
0
votes
2answers
361 views

How to restore deleted pages/posts?

I recently deleted some pages in my wordpress site. Now I want to re-store them. How can I do this? Any suggestions will be appreciated. Thanks in advance
0
votes
1answer
118 views

Is get_posts() more efficient than The Loop?

In category.php, I want to get list of posts in that category. I found two ways: using get_posts($args) and The Loop. get_posts() way $args = array ( "category" => ID ); $posts = ...
0
votes
0answers
35 views

Advanced meta query help

I want to get posts according to the following logic: "If post status = publish or pending then get all records which have a meta value of less than todays date. If the post is in trash, get it ...
0
votes
1answer
121 views

custom post type upcoming post and past post

I want to retrieve inside my archive-CPT.php most recent upcoming post ( post with status of future) and past post (oldest published post). This is how my archive-CPT.php is looking like: <?php ...
0
votes
1answer
32 views

How do I get only a certain number of images from a post (minus the featured image)?

I have the following code (see below) that lists all attached images from a post. I'm trying to alter this code to only list the first five images, and also to exclude the featured image from the ...
0
votes
1answer
44 views

Exclude categories from homepage not longer working

I was using query for excluding categories from my homepage without problems until this week. I'd like to know the reason of the change and a better way to get this. I was trying also diverse ...
3
votes
1answer
253 views

Get all authors with at least one post of 'custom post type'

How can i achive that? I found count_user_posts and get_users, but how would I merge them into the desired result? Do I really have to use a WP DB Query?
0
votes
1answer
137 views

Retrieve posts in custom post type and specific taxonomies

I'm struggling with what seems like should be so simple looking at the codex. I have a custom post type, let's call it 'portfolio'. A custom taxonomy for that, let's call it 'clients'. I can use ...
0
votes
1answer
45 views

How to query posts to include specific pages of one post type, and all pages of another post type?

I'm having trouble figuring out how to query all posts from the post type "events", as well as including four specific pages in the loop. If I use the "include" parameter, it only returns the ...
0
votes
0answers
87 views

WordPress Page Template to Display Page Title, Custom Field, and Date

I'm currently attempting to create a page template that will display all posts by the current logged in user, a particular custom field from those posts (i.e., Item Status), and the dates those posts ...
1
vote
3answers
2k views

get_posts only children from certain parents

I have parent posts (custom post type hierarch=true) with ID 1, 2, 3, 4. The parent posts with ID 2 and 4 have child pages. I need to retrieve only posts 2 and 4 and all of their child pages. ...
0
votes
1answer
170 views

Test if a post exists by category and date

I would like to check outside of the loop, if a certain post exists in a specific category and from a specific date. The function get_posts() -- if I get it right -- allows me to check, if there are ...
1
vote
1answer
143 views

Wordpress count child posts of each parent custom post type and use in json array for google maps jquery plugin

So i have been looking for a couple of days now and cant find a solution to this anywhere. It is a fairly bespoke request from a client... I am using a jQuery google maps plugin to add markers for ...
0
votes
1answer
42 views

Yet another get_posts() in explicitly defined order problem

I am creating a 'loop' that needs to display pages (not posts) in a defined order of ids. What I did till now is: <?php $ids = array(434, 814, 3660, 3235, 99, 1002, etc.); ...
72
votes
3answers
42k views

When to use WP_query(), query_posts() and pre_get_posts

I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit ...
0
votes
2answers
254 views

pagenavi shows alot of pages calculated from all posts in the site with query_posts

I need to excute posts from 2 seprated keywords using s=keyword with get_posts, but only searching in titles. I found this answer. I created a custom template to use it in single page. Then I used a ...
0
votes
1answer
199 views

Can't pull posts of a Custom Post Type based on the custom taxonomy of the CPT

My question is about retrieving custom post types via get_posts, when custom post types also have a custom taxonomy. I can use get_posts to retrieve all posts of a custom post type, but when I attempt ...
0
votes
1answer
33 views

Search for pages with permalink

I'm searching for posts this way $args = array( 'name' => $permalink, 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => 1 ); $posts = get_posts( $args ); ...
0
votes
0answers
93 views

Wordpress sort custom field values in alphabetical order

I am using WordPress Custom Content Type Manager to build a Literary Agency website. The page I'm stuck on is the Authors page which displays thumbnails of all the books related to the author. The ...
0
votes
0answers
36 views

can't reset get_posts

I have three loops in my theme that I want to use to get menu items for a lunch, dinner and wine list menu. The first loop worked fine but when I added the second one, the system broke. I did some ...
0
votes
1answer
36 views

Why only one post (and no pagination) on this variation of the loop?

This is my WP loop: // fetch latest news stories $paged = (get_query_var('page')) ? get_query_var('page') : 1; $posts = get_posts(array( 'numberposts' => 3, 'paged' => $paged, )); // ...
0
votes
1answer
217 views

Problem: ( kriesi ) pagination doesn't work in homepage [duplicate]

When I set this template as homepage, pagination doesn't work. I see the buttons, but when I click the button for page 2, nothing happens, doesn't go on page 2, it still remain in page 1. What is ...
0
votes
1answer
107 views

Retreive tags from attached post for media on page

I am working on a custom template file that pulls all images in my Media Library with a specific tag. I was able to get this working with some help from the community, it also shows the title of the ...
-1
votes
1answer
162 views

get posts based on category and post meta

I am coding a Live Show box for a radio website to show who is on air and who is up next. I've been using the get_post function to retrieve posts based on the category (in this case the day of the ...
1
vote
2answers
140 views

Wordpress not opening posts with only numbers if permalink is post_name

Someone knows why this happens? For instance, I have a post called 1987, but it does not open it when I click on the link. When I use a different permalink structure, it opens it. Why is this and how ...
0
votes
1answer
280 views

Select post from dropdown and add query args not working

The behavior of the below should be that the user makes a selection on the dropdown box and the page refreshes with a query arg of editevent=1 and also passes a value of the post ID with the selection ...
1
vote
1answer
1k views

get_the_content(“more…”) returns full text

I'm creating shortcode [latest_post] and want to show post date, title and short content. (content has "more" separator). Here is code: function shortcode_latest_post() { global $post, $more; ...
2
votes
0answers
393 views

Get Recent Posts by Date in Multisite

Everything in explanation is about CDTuts I've created a WordPress Network and I want is to get the recent posts from all of the selected subdomain blogs. I need to get the latest All organized by ...
0
votes
0answers
47 views

Trying to combine a variable together

So I am not 100% sure if the is feasible so hopefully some one can point me in the appropriate direction. I am using the Advanced Custom Fields plugin and on my custom page template I am using the ...
4
votes
2answers
536 views

How to get current post ID in quick edit callback

This question is related to another previously asked question, which is a follow up on an answer. Task As I want to extend QuickEdit to be something really awesome (and more than just quick edit), I ...
0
votes
1answer
426 views

Get title of post image is attached to

So I found this post: Find the post an attachment is attached to and implemented Chip's suggestion but having a weird outcome. I am trying to pull the title of the post that the specific image is ...
2
votes
2answers
1k views

How to get all children and grandchildren of a hierarchical custom post type?

I need to get all sub-posts of a specific (root) parent id. get_posts( array( 'numberposts' => -1, 'post_status' => 'publish', 'post_type' => 'microsite', 'post_parent' => ...
0
votes
2answers
105 views

Transient Loop Not working as expected

So I created a transient object that used get_posts() to get a series of posts based on some argument. Well the transient was stored - it was created - YAY - now I tried to write this loop: public ...
0
votes
1answer
284 views

get comments and get posts in loop

I need to get posts done by specific users and get also comments done to these posts, so far I can get the posts and comments but can't get how to do it in loop properly, because now I get the same ...
-3
votes
1answer
221 views

Get all posts without tags

I'm working with a tag plugin. Is there a WordPress way to get_posts or query all posts that have no tags?
0
votes
1answer
57 views

How to show only 1 post from a specific category on the front-page

On my front-page i have a 3 col block section below the fold. The final and third column is an excerpt of the most recent post from my art category blog, hopefully this is clear up until here in terms ...
0
votes
2answers
266 views

Add Filter not working with get_posts

While tweaking the "Bryans Childpage Thumbnail Generator" plugin, I am applying filter (with pagination) to the get_posts for WP Pages (post_type=page), but its not filtering at all. Here is the code: ...
0
votes
0answers
113 views

show/hide attachments

Is there a way to show/hide attachments in my case images on a post. What I want is to mark an image as "hidden" and then only show it to the admin and hide hidden images from a normal user I know ...