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

3
votes
2answers
207 views

Very slow query

This query works, but it takes upwards of 20 seconds to run on a Quad Core dedicated server... How can I optimize this? $slides=get_posts( array('post_type' => 'any', 'numberposts' => 5, ...
0
votes
1answer
179 views

Why posts array is empty?

I try to get posts that either do not have a custom field set or if set have a value not like a given parameter. Here is my code: $args_included = array( 'numberposts' => 1, ...
0
votes
1answer
244 views

Query custom posts of logged in user only

I have a custom post type setup called website I thought using the code below would display only the logged in users posts but it's displaying all of the custom posts even those not belonging to the ...
0
votes
1answer
2k views

List all posts in a category with query_post() function

I'm a C programmer, konw little about PHP. I built a Blog with wordpress. Yestoday, I try to create the page www.abc.com/server, this page would list all posts which belong to server category. I ...
0
votes
1answer
115 views

Add ul to its children with get_posts

I want to add a ul to the list when a page have a child, Im making a foreach on all the post_types so i don't think that i can use something like wp_list_pages. I have been trying to sort this out but ...
0
votes
1answer
165 views

Showing posts from 2 categories only on category.php

got myself in a bit of a pickle. I want to display posts on category.php from the categories 'latest news' and 'custom models' only. The other category, 'press releases' is shown in a separate column. ...
0
votes
3answers
686 views

Add class to every other posts using get_posts

I am currently using this little loop to display a list of posts using the "events" custom post type <?php global $post; // required $args = array('post_type' => 'events'); ...
1
vote
1answer
312 views

My post repeats itself on the second page [closed]

Hey the way i have my index coded is that it shows one full post and the rest of the post are excerpts, but when i click previous the 2nd page shows the same post from the first page, what can i do to ...
0
votes
1answer
434 views

Get random custom posts from a custom post type

I created a custom post type named predic, I’m trying to get within one of this post other four random posts from the same custom post type. I used this code, but I keep getting the same post I’m in 4 ...
0
votes
1answer
144 views

pre saved posts query from db options table

I found a question about magazine style front pages that queries always only 1 post (or custom_post_types, etc.) from a whole load of different categories, tags or custom taxonomies. I thought about ...
0
votes
1answer
170 views

populate array with posts

I want to generate an array of custom post types to add it to a options array. I'm doing this to show a checkbox group populated with custom post type. I have this array: 'options' => array ( ...
4
votes
2answers
454 views

the_title() and the_permalink() won't work on AJAX calls

I've run into a strange problem. I have a custom loop built with get_posts that works fine when loading the page normally: <?php $rows = get_posts(array( 'post_type' => ...
0
votes
1answer
269 views

Get posts from current category?

How can i display 5 posts from current category (exclude current post). Order by post time. Example: To day news to reading 3 (12/11/2012 - 8:10 PM) To day news to reading 2 (12/11/2012 - 6:07 AM) ...
0
votes
1answer
390 views

Show last post from multiple categories using wp_list_categories

I have the following code that lists out the children categories on a separate page when you click on its parent category. The code renders a list like so: Home › Archive for IQ Issue 7 Journal ...
2
votes
1answer
5k views

get all posts ID from a category

Problem: I need to get an array of ID's of posts from a given category If the category have any posts. This is to be used on a plugin options page. So far I have: $posts = ...
1
vote
1answer
6k views

Wordpress pagination with get_posts?

I need to make adjustments to a horribly written WP theme that (a custom theme that was written in tables, and bad code). The theme has several custom templates, but pagination wasn't used and ...
0
votes
2answers
184 views

How to Make infinite loop of post

I am using Post contents as a slider contents, i need to make the post infinite number of loop, ie, If i view the last post after that first post should display and before first post the last post. ...
1
vote
1answer
544 views

Help with WP_Query - Too many mySQL queries

I need some kind of help with wp_query. Am I doing something wrong? I am getting a lot of mySQL queries, while building a new theme. My WP_Query is: <?php $args = array( 'post_type' => ...
1
vote
1answer
102 views

How to optimize my query filtering out unwanted data?

I use get_posts ($arg); to query the post table. Usually I need only three fields: post_title, ID and post_excerpt. But the data returned are many more, including post_content that is usually huge. I ...
0
votes
1answer
426 views

get_posts() and global variables

I was reading this post: When should you use WP_Query vs query_posts() vs get_posts()?, which seems to have become the go-to post for understanding the difference between the different functions for ...
0
votes
1answer
1k views

Display post details by post ID

I need to display post details by ID on front page template (front-page.php). On the front page I want to display the post’s title, excerpt & featured image. I have tried to do that but no idea ...
0
votes
4answers
2k views

Displaying multiple post types on home page

I've read several examples of how to do this but I still can't get it to work - each time I use get_posts() it seems to only keep and display the first set of results. loop.php function ...
1
vote
1answer
161 views

Logged in user ID as post ID

Is there a way to automatically insert the current user ID as the post category name or maybe have WordPress display only the post with a category name that matches the current logged user ID? ...
1
vote
2answers
200 views

Ordering posts by metadata

In my plugin, I use these instructions to obtain a list of posts: $args = array( 'numberposts' => -1, 'offset' => 0, 'meta_query' => array( array( ...
1
vote
1answer
667 views

Problem with get_posts, tax_query and counting the number of posts

I want to count the number of posts that has simoultaneously 3 different taxonomies. THe code i'm using is this: $products = get_posts(array( 'post_type' => 'products', 'posts_per_page' ...
0
votes
1answer
114 views

Displaying posts on Homepage

I am wondering how to add a column to my homepage that shows the five most recent posts from the blog page located under the "Latest News" heading. Here is the link to my development site. ...
0
votes
1answer
116 views

Wordpress pagination URL posts not load

I set up wordpress newly and add next previous pagination in home page using following code next_posts_link('Older Entries »', 0); previous_posts_link('« Newer Entries', 0); Pagination URL work ...
1
vote
1answer
200 views

WP_Query() and get_posts() can't handle over a thousand posts?

So I have a search function that just fetch custom posts and return them as a list. function search() { // post query args $args = array( 'post_type' => 'post_type', ...
0
votes
1answer
304 views

Custom field to array?

I have a posts query that queries posts by ID but want to select those posts by enetering a custom field. Here is the query and where I want to put the custom field: $query_args = ...
2
votes
1answer
222 views

get_posts inside cron

Edited to rewrite my question I'll try to be as clear as possible, as I need to get this resolved quickly. I disabled WordPress' cron, and added a real cron job on my server to call wp-cron.php ...
0
votes
1answer
328 views

Meta query: get posts with value in a multidimensional array

I have a custom post type, Album, which has a custom field called 'tracklist'. Tracklist is a multidimensional array which contains a track title and track link, like so: $tracklist = array( [0] ...
1
vote
1answer
289 views

Setting pagination for images attached to a post

I am trying to figure out how to paginate a post for it's images. I have a custom post type set up to act like a gallery - images only. And would like to paginate the images. I am having a hard time ...
1
vote
1answer
388 views

Exclude images from “inserted into post” when trying to get attachments

I have here the coin-slider which takes all pictures from the gallery. I get the attachments through the following code: $attachments = get_posts(array('post_type' => 'attachment', 'post_parent' ...
0
votes
2answers
733 views

How to get single post by one author?

I just want to get the most latest posts by an author. I am using get_posts at the moment but I notice it doesn't take an author argument, so how I can I specify my author? $args = array( ...
0
votes
1answer
181 views

How to create a custom loop ordered by Categories on a Page Template?

Ex. Category 1 Post 1 Post 2 Post 3 Post .... Category 2 Post 1 Post 2 Post 3 Post .... Category .... Post 1 Post 2 Post 3 Post ....
0
votes
1answer
744 views

get_posts not finding argument: post_name

I am digging up posts with a specific slug: Where $postSlug = 'abc' $args = array( 'post_name' => $postSlug, 'post_type' => 'post', 'post_status' => 'publish' ...
0
votes
1answer
42 views

How do I display the index position of a post from a custom post type?

So I have a custom post type (ex. songs) and have a few posts that I created for this post type. I want to display them on a webpage in order (ex. 1, 2, 3, ...). How do I get the index position and ...
0
votes
2answers
396 views

get_posts cannot grab from specific category

I'm using get_posts to grab list of posts from custom post_type. I also want list to be limited to specific category. So I tried: $postslist = ...
3
votes
1answer
144 views

How to get_posts having post thumbnail?

I have following code: $posts = get_posts(array( "meta_key" => "special", "meta_value" => "surprise", // "has_post_thumbnail" => true, // how to do that? )); What should I do to ...
1
vote
1answer
968 views

How do I pass a post ID to the page URL?

I am using a form (gravity form) on my site. The form is inserted in a page (called form_page) on the users dashboard when they are logged in http://example.com/dashboard/form_page I am using a ...
0
votes
4answers
272 views

Why always one post missing

In my custom query, every time I query for posts from a particular category using WP_Query() and the category has 10 posts for example, I seem to be missing a post. So querying for 10 posts only ...
3
votes
5answers
11k views

How to get all posts related to particular category name?

I am developing one project and in this project i have to display all the posts related to particular category name. I have searched a lot but i haven't got any idea to implement this. How can i do ...
0
votes
1answer
198 views

get_posts() seemingly ignoring post_type

I am trying to grab posts of post type "leads" (see below for the code I am using) however the query produced (obtained via debug queries) is including the clause 'where post_type in ("leads", ...
2
votes
1answer
921 views

Is it necessary to reset the query after using get_posts()?

Is it necessary to reset the query after using get_posts() ? I have been looking at this page and I don't see any reference to get_posts() ... I can't make it out for sure from this page either. I ...
2
votes
1answer
1k views

WP_Query vs get_posts

I have read a number of questions on SE regarding these but I still can't figure the exact difference wrt usage. Would it be true to say that I would probably use WP_Query for the majority of ...
0
votes
2answers
754 views

attachments with tags and get_posts

having problems with filtering a posts attachments by tag... It worked fine until i added the tag__in arg (and other variations of it). $vidArgs = array( 'tag__in' =>5, ...
0
votes
1answer
132 views

Execute PHP function inside the admin area

I want to ask if there is a hook for executing php inside the admin area, my problem is I'm trying to do the get_posts wordpress function inside a popup frame using the thickbox jQuery plugin, using ...
0
votes
1answer
710 views

get excerpt without images

Is there any way to not get the images with get_the_excerpt()? I am using a my_recent_post() function to pull posts onto the home page and I don't need to have it pull the images within the posts, ...
1
vote
1answer
526 views

Getting a custom post type image using 'get_post_custom'

I am trying to echo the image src of an image I have uploaded for my custom post type outside of the while loop. I have used the following: $custom_fields = get_post_custom($_GET['id']); I can ...
0
votes
1answer
91 views

Select objects from get_posts()

How can I select the first/last object from the list returned by get_posts()? How can I select the preceding/following object relative to an arbitrary object in the object list returned by get_posts? ...