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
2answers
34 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
21 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
2k 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
19 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 ...
2
votes
1answer
862 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 ...
1
vote
1answer
37 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
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
439 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
32 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
23 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 ...
0
votes
2answers
456 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 ...
2
votes
3answers
6k 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
39 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
28 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
26 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
143 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
42 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
30 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
28 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
49 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
81 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
68 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
653 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
10 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
61 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
32 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
47 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
26 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' => ...
271
votes
7answers
100k 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 ...
0
votes
0answers
23 views

Get Custom Post Type posts on normal edit-posts and pass to TinyMCE

I am following a tutorial for adding a dropdown list in tinyMCE editor. In the end I would like to have a Select list similar like it is in this image , but populated by post titles from Custom Post ...
7
votes
1answer
123 views

Alternative to get_posts() due to multithreading cache crash

I am using pthreads to creat multiple threads. Each of those threads at one point tries to use get_posts() as follows: $args = array( 'post_type' => 'post', 'post_status' => 'any' ); ...
1
vote
1answer
30 views

WordPress takes too long to show 404 error on images (on LEMP stack)

I have installed WordPress on LEMP stack on DigitalOcean and noticed that all the 404 images on the pages are taking too long to show a 404 error message. Those images are not existing so it will ...
0
votes
0answers
28 views

Getting posts for a category

I have a menu made up of categories, click a category shows the users list of articles beloging to said category. However I seem to have stumbled across a problem if a post belongs to 2 or more ...
0
votes
1answer
46 views

offset and max_num_pages in pagination gallery

I rewrote the code galleries and stopped at the pagination. How can I get the maximum number of pages? at the moment I can not define it, and put a test for the number 5. (Here "for ($ i = 1; $ i ...
0
votes
3answers
44 views

How can I use wordpress functionality outside of WP framework

I require to retrieve a list of the recently created blog posts or any Query-based usage of WP posts inside my PHP website and not within WP framework. I am new to Wordpress and stucked here. I ...
0
votes
2answers
40 views

Custom Post type Query post is not working

I created a custom post type tickets, than I added few tickets in it. But with the following code, I tried to show list of tickets submitted by the current user and its not working for me. global ...