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

1
vote
1answer
19 views

Return Taxonomy/Term Information with Posts (WP_Query/get_posts)

Is it possible to return taxonomy/term information for posts along with the posts themselves when querying with get_posts? I have around 150 items I am querying so I don't want to loop and pull each ...
2
votes
1answer
877 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
17 views

Display Posts in Admin Page

I create a admin page. Now I need to display posts in that page. Should I use WP_Query or get_posts()? (Pagination should be there) Note : I have read When should you use WP_Query vs query_posts() ...
0
votes
2answers
3k views

Pagination with get_posts seems to work but links not showing

I've a custom page template where I want to query 2 posts from a post type and 1 post from another post type. I have it set up like this: $paged = get_query_var('paged') ? get_query_var('paged') : 1; ...
0
votes
1answer
449 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
5answers
582 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 ...
0
votes
0answers
41 views

get_posts by category_name does return all posts

When I query (using get_posts) by category_name (string) I get all posts returned of any category. However when I select by category (int) I get the proper results. What could be wrong ? [edit] ...
1
vote
2answers
1k views

get_posts not working as expected

I'm trying to get posts from 3 different categories and list them on the front page: // Carousel articles $args = array( 'numberposts' => 3, 'orderby' => 'date', 'category' => ...
0
votes
2answers
473 views

get_posts showing only 5 posts. (nopaging and posts_per_page -1 not working)

I have this piece of code which works but it's showing only 5 posts (with custom taxonomy) where should be 7. If I hit the tag url, it shows the 7 registries, so the problem it's in this code and its ...
3
votes
2answers
2k 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, ...
4
votes
2answers
13k views

Get posts under custom taxonomy

I am not getting the posts under custom taxonomy(fabric_building_types).I am getting cat_id and cat->name also but not able to get the posts. $args = array( 'type' => ...
0
votes
2answers
48 views

Certain number of posts with certain excerpt length

Could use some help... using this code to call up a custom number of posts from a certain categorey and only want to display the first 15 characters. However, it is showing the same excerpt on each ...
0
votes
2answers
4k views

Custom Taxonomy with tax_query

So I've created a custom taxonomy type with a plugin (CMS Press) and now I'm trying to get all of the posts with the taxonomy terms in that taxonomy. My get_posts looks like this: $args = Array( ...
0
votes
1answer
36 views

Orderby taxonomy term id using get_posts not working

I'm looping through a series of custom post types and then grouping those by a taxonomy term. That is working great, however I have not been able to order these groupings by term_id. I used a ...
0
votes
1answer
3k views

How to get custom post type title, excerpt, thumbnail and permalink by post ID?

I have to generate several "loops" to get the title, excerpt, thumbnail and permalink of a custom post type 'charity' by post ID, because I will have multiple posts (charities) I need to target with a ...
1
vote
0answers
26 views

Get attachments for posts that belongs to a specific category

I am trying to get images which are used by a post belonging to the specific category. For example if I have plants, mushrooms and animals as post categories, I only need to retrieve images that are ...
1
vote
1answer
38 views

Filter the content from a post globally immediately after is fetched from the database

I am encrypting the content of a specific custom post type whenever i am updating or creating it. That is working fine. Is there a way to globally decrypt the content for all WordPress read ...
0
votes
3answers
2k views

Get id of category from drop down menu

Im trying to get the category ID from wp_dropdown_categories();and then pass the ID into a loop to have it output posts titles from that particular category. I currently have this: <form ...
0
votes
0answers
28 views

I want to add values ​of a function in all posts in a particular category

I want to add values ​​of a function in all posts in a particular category, I get exactly what I want, but not the old problem appears in post_content(edit mode em dashboard) ...
0
votes
1answer
34 views

Conditional Tag for has post [closed]

I am quite new to all the programming, and I am now stuck with the following. I installed the plug-in If Menu which lets you show specific menu items when Conditional statements are true or false. I ...
0
votes
1answer
25 views

Remove Featured Images from Posts Older Than a Certain Date

I run a network of sites, with hundreds of editors, and lately we've had image copyright trolls coming after us. Most of these images are a year old or older, so we're looking to remove all images ...
2
votes
3answers
7k views

How to use the_posts_navigation for wp_query and get_posts?

WordPress have the_posts_navigation function since 4.1.0. But I don't know how to use with wp_query or get_posts. the following code is in a template file of page.wp_query method: <?php if ...
0
votes
0answers
47 views

WP_Query meta query not returning results as expected

I'm trying to run a get_posts query to determine if a users ID is either set as a meta key value or is included within the array of another meta key for an event on a given date. I am passing ...
0
votes
2answers
30 views

get posts that doesn't contain a specific tag

I want to get all the posts that do not contain the tag 'index'. How can it be done? I mean in the reverse of get_posts(array('tag' => 'index')) Thank you
0
votes
1answer
30 views

wp json api - get posts by category

I have added a method to core controller of WP JSON API plugin that extracts the posts by category wise, however getting only one category data. Please find the code below. public function ...
0
votes
0answers
158 views

$wpdb->query(update) not working as supposed when passing GET request in the where clause

I have made a table 'wp_mostfavourite' in wordpress database, it has got three fields, 'serialno', 'postid', 'counts'. The 'counts' is supposed to be increased by 1, whenever the following query is ...
1
vote
2answers
2k views

get_posts and multiple categories

I have created a custom query in hopes of showing the top posts from some child categories. The query has a big flaw: some posts belong to two categories; but, even if they get marked in BOTH ...
0
votes
1answer
45 views

Group by custom field value (start and end times)

I have the following loop that is outputting a schedule for a conference. At the moment it's looping through a custom post type, grabbing the info, then outputting it in a block. So essentially each ...
0
votes
4answers
1k views

get_posts with multiple categories

If I do a get_posts() with category set to 1,2 I will get all posts in category 1 OR 2. If i want all posts whit both categories, that is 1 AND 2, how do I make that request?
0
votes
1answer
32 views

Get_posts not returning any posts when used with switch_to_blog

I'm attempting to pull in some order information from the "shop_order" post_type. This is on a multisite network, so I'm using switch_to_blog(1). When I set the post type as "post" it works great and ...
1
vote
1answer
24 views

get_posts that match a user-specified value on a page

On each page, I want the admin to choose which case history post summaries will be displayed depending on the post category. My code below works but it is very clunky if you have lots of categories. ...
0
votes
1answer
36 views

Create a hierarchical loop at predefined markup requirements

I try to achive this in wordpress based on my theme: fullpage.js demo So I have a predefined markup for vertical sections (parents) and one for horizontal slides (children). Parents only contain ...
0
votes
1answer
34 views

meta query not retrieving posts

I am attempting to use get_posts() to retrieve posts that have certain topics attached to them, in my custom post type named 'leaders' Here is my query. $args = array( 'post-type' => ...
0
votes
2answers
54 views

Check return value of get_posts

I've been trying to change my WP_Query to get_posts methods. But I am not really sure how to check if get_posts is null or have a value. How can i transform this WP_Query checker to appropriate ...
0
votes
1answer
116 views

Get posts by language in Polylang plugin

I use the Polylang plugin to translate my website in Italian and German. How can I get the latest post in Italian? I'm using the arguments below to get the content of the post, which afterwards I ...
2
votes
1answer
79 views

How to get post content by calling ajax?

I am working on a plugin .I have a custom post type team.Custom post has four posts of different categories.I used this code to send post id of each using ajax. $(document).ready(function () { ...
-2
votes
2answers
675 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? EDIT I had already queried the WP Codex, search Stackexchange and Google for a related ...
0
votes
1answer
11 views

Find owner of coupon

I'm attempting to run a function for a user if they have a certain coupon. I'm using the plugin Smart Coupons to generate coupons with prefixes and suffixes. I can get a list of all the coupons in ...
1
vote
1answer
65 views

Meta Query with date and time on the same Day before given time

I have a metaquery for a custom post type "events". Their start date is stored as a meta field in this format: 2016-02-05 19:00:00 These are my query args: $args = array( "posts_per_page" ...
1
vote
1answer
34 views

Meta Query returns wrong number of posts

I am using this meta query inside a category: $args = array( "posts_per_page" => 12, "post_type" => array( "event", "post" ), "post_status" => "publish", ...
4
votes
3answers
683 views

List most recent image uploads, but only for specific custom post type

I can get a list of the most recent image attachments like so: $attachments = get_posts( array( 'post_type' => 'attachment', 'posts_per_page' => $number, 'post_mime_type' => ...
0
votes
1answer
55 views

Query get_posts by level depth

I have a page structure like this: -- Asia ---- China ------ Shang Hai ---- Hong Kong -- Africa -- America ---- USA ---- Canada I want to use get_posts to get all posts that I marked in bold ...
0
votes
0answers
29 views

get_posts ( $args) failing when called by AJAX

Here's my code: function ajax_test(){ $default_workout_category = 61 //Hardcoded category for testing $args = array( 'category' => $default_workout_category, 'orderby' => 'title', ...
1
vote
1answer
26 views

Get posts by name and taxonomy term

How do I get all posts that has a taxonomy term and a specific name/slug? I have tried with the following arguments but without getting the wanted result. What am I missing, how can I combine the ...
4
votes
2answers
4k 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' => ...
275
votes
7answers
101k 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?
0
votes
0answers
15 views

Decrement term in for each

So I am catching custom posts in wordpress by for eaching my custom terms. To get a post from the next term in the loop I use $terms[++$key]->name and it all works fine. However when I want to do the ...
2
votes
4answers
4k views

How to return only certain fields using get_posts()

I'm trying to get only the fields that I need using the get_posts() function in WordPress. I currently have the following code: $posts_args = array( 'orderby' => 'post_date', ...
4
votes
2answers
12k views

How do I get posts by multiple post ID's?

I've got a string with post ID's: 43,23,65. I was hoping I could use get_posts() and use the string with ID's as an argument. But I can't find any functions for retrieving multiple posts by ID. Do I ...
1
vote
5answers
8k views

get_post random and order by not working

I have this code that returns list of post title as links, but when I add the 'orderby' and 'order' parameters - it returns results but 'orderby, order, rand' do not work, can anyone tell me what I'm ...