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

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 ...
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 ...
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
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 ...
0
votes
1answer
745 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 ...
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
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
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", ...
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 = ...
2
votes
1answer
923 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
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? ...
2
votes
3answers
861 views

Post count per (day/month/year) since blog began

I'm looking to echo the number of posts per month since the blog began, and for months where there was no posts echo '0'. This is the output I want: January 1, February 3, March 8, April 3, ... ...
0
votes
1answer
399 views

How to reset post data properly

I have this piece of code that I am calling within the loop to get image metadata ( title/caption and description ). It works fine but it only works for the first post in the loop. So I assume it ...
1
vote
2answers
91 views

How do you Query posts with nothing in common?

We can get multiple posts manually in a page, but that's generated in a template, AFTER the default query returned something else (page/post, etc) How do you query multiple posts in a public query, ...
1
vote
1answer
275 views

Show recent posts from one category on a non-WP site

I'm trying to move back to WP for our blog, after struggling with a clunky CMS for a few years, but we'll be sticking with that CMS for the rest of the site. Is there a plugin (or code) that I can use ...
0
votes
2answers
447 views

Divide the list into two columns (get_posts)

The function below lists posts based on custom field. The result is involved in a list <li></li>. What I would like to do is count how many list items there are, then divide it into two ...
0
votes
1answer
165 views

not empty categories don't show in menu [closed]

I'm trying to resolve a problem i have showing category posts. I have added a category to my main menu, eventhough it has posts - in the basic theme it doesn't show, in my theme - it shows as a link ...
1
vote
0answers
313 views

How to reload a select box of posts dynamically?

I'm using custom meta boxes for a project. I have created a custom taxonomy (select box) and I have another select box populated with Posts. I need to only load the posts based on the selection of the ...
1
vote
1answer
2k views

get_posts with meta_compare='LIKE' not working

I am using the following code: $tolettpe = "Sale";//default if($_REQUEST['tolettype']) $tolettpe = $_REQUEST['tolettype']; else if($_REQUEST['srch_type']) $tolettpe = $_REQUEST['srch_type']; $args = ...
0
votes
1answer
80 views

get_query stops working after post filter

I'm currently trying to set up some filters for a custom post type within my admin. The custom post type is 'players' and I'm filtering them by another custom post type 'teams'. To create my ...
0
votes
1answer
251 views

Display a random customposttype2 excerpt in single-custompostype1.php that shares same taxonomy

OK - Looked everywhere for this one. Details: Custom Post Type #1 = 'product' > registered taxonomy 'productranges' Custom Post Type #2 = 'testimonial' > registered taxonomy 'testimonials' Both ...
1
vote
1answer
237 views

Get posts inside Get terms problem

i have a get_terms which loads correctly. inside of it i have used get_posts. then using get posts i am trying to get each post tags (and count <= not currently inside this script) <?php ...
0
votes
1answer
246 views

What is the p parameter in a get_posts() parameter array?

I've seen code that looks like this: get_posts(array('p' => $thumbnail_id, 'post_type' => 'attachment')); What is the definition of the p parameter and is it documented anywhere? I can't find ...
0
votes
2answers
166 views

Sorting posts by specific order

I have a custom post type and I want to be able to control the order that the posts are displayed by defining the order in an array, and then checking the posts meta_value against the array to see ...
1
vote
1answer
1k views

latest 5 posts using switch_to_blog loop

im sure i must be doing something wrong and would really appreciate a little help. I am trying to loop through all of my Sub Dir "Multisite" blogs using switch_to_blog, below: global $wpdb, ...
1
vote
2answers
105 views

Why is querying posts messing up my pages?

I am working on a theme at the moment and I have set up a post template. This post template is linked to some custom post types. When I query_posts for my post type on the actual post template ...
1
vote
1answer
343 views

How can I paginate a list of related posts?

My client's home page displays a paginated list of posts with thumbnails. Each list item, when clicked, navigates to a single post or page, and then uses a separate query to generate the same list of ...
1
vote
1answer
397 views

If meta key exists in get posts function otherwise create it

The following code fetches posts with the meta key home telephone numbers. $metas = ''; $args = array( 'numberposts' => 1, 'post_type' => 'electors', 'orderby' => ...
0
votes
2answers
613 views

Add filter to get_posts

So I am attempting to filter out certain posts in the get_posts call. Essentially, I want to be able to specify a certain block of posts, and only get the posts that correspond with the block. Right ...
0
votes
2answers
438 views

Can't sort get_posts by post_mime_type

I'm trying to run a query to get all attachments and I'd like to sort by the post mime type. This query isn't working. Any ideas? $query_args = array( 'post_type' => 'attachment', 'numberposts' ...
0
votes
2answers
717 views

get_posts displaying wrong permalink for “continue reading” link

I lifted the "continue reading" link functions from the Twenty Eleven theme and for the most part, it is working (works in RSS feeds). I created a shortcode to display the latest post on the front ...
0
votes
1answer
65 views

Use get_posts() with 'post' and 'page' queries at the same time?

I'm trying to grab all posts which are 'posts' and not in category '3' and '5' and which aren't 'pages'. Is this possible to do using one single get_posts()? Because I'm querying both actual posts and ...
0
votes
3answers
151 views

Delist entries in the_loop

I am trying to add a delisting feature to my WordPress network. Posts which are delisted would not appear in post lists, but would still be visible if accessed directly. I've written a plugin that ...
2
votes
2answers
161 views

How to get 4 Posts after the 5 most recent ones

Well, I think the question might be a bit confusing. But well, I want to get the recent 4 posts, ignoring the first five recent posts. So in short the sixth, seventh, eighth and ninth - most recent ...
0
votes
2answers
161 views

loop inside a loop : search for posts in the same category

Could someone tell me how i could make this work? i have a loop, and i would like to create another loop to find the other posts from the same category : but this does not work : <?php while ( ...
0
votes
1answer
45 views

How to pull a list of posts in a category while exluding posts in subcategories of the category

I'm using a get_posts() call to pull a list of posts in a specific category. However, the recordset also includes posts in subcategories of the target category. How can I exclude subcategories from ...
0
votes
1answer
217 views

Hide gravity forms

I have gravity forms set up on my site and I am wanting to hide/show a form based on whether or not the user has posted an entry into the form/database. If they have made an entry, then I want to hide ...
0
votes
1answer
1k views

Query only Posts from Both of Two Category?

I have 3 categories, 1.OnGoing projects(cat id='5') 2.Completed Projects(cat id='6') 3.Upcoming Projects(cat id='7') and also i have another 2 categories:(Not a Sub Category) chennai (cat ...
0
votes
1answer
2k views

How to query custom post type by term?

This seems trivial but I can't get it to work. Here's my code: $args = array( 'numberposts' => -1, 'eventcategory' => 'nice-events', ...
0
votes
2answers
243 views

List 'n' number of posts from a Tag, each with a different class or ID

I want to list 'n' number of posts (ordered by latest first) -- post's title linked to the post's permalink -- from a tag on my WordPress blog. I also want to assign each link its own class or ID. I ...
67
votes
3answers
33k 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 ...
1
vote
1answer
91 views

Sort posts by most recently modified

Is there a way to list posts in the order in which they were modified? For example; A user posts 5 posts (#1 being the oldest and #5 being the newest), by default they would be listed with #5 being ...
0
votes
3answers
79 views

Is it possible to retrieve a post and its metadata at the same time?

I usually use two steps to retreive a list of posts and the associated metadata: call get_posts(or a custom WP_Query), and then loop through each post returned and retrieve each posts metadata one by ...