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

2
votes
2answers
264 views

How to show next Post Thumbnail image in WordPress using current post id

i make a wordpress theme i make a grid structure show below i have this grid structure it contain two rows and every row has three column i want to show my wordpress random posts in this grid ...
0
votes
0answers
184 views

How to get post content by get_posts function?

I'm newbie at Wordpress and now I need to get the post content in events plugin. I have simple array: $event = get_posts(array( 'name' => $events_array[$i], 'post_type' => '...
2
votes
3answers
149 views

Order posts according to user defined order for meta values?

I have set up some CPTs and storing a meta key/val for each of them. When I get those posts, I need to order them by the meta value, but, the order of the meta values will be defined in an array by me....
0
votes
1answer
165 views

Use not custom fields in get_posts() meta_query?

Is it possible to use not custom fields in get_posts()'s 'meta_query' to use a or-relation statement with a custom field and a category id? Like this: $args = array( 'posts_per_page' => 6 ...
0
votes
2answers
455 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
0answers
44 views

How to Create Random post once in a day

Hello Guys I am having issue with the code i found here I wanted to add specific custom post type to be randomized once in a day and i used the code i found here but that repeating the content on ...
0
votes
1answer
33 views

get_posts $args won't accept array as one of the criteria?

The goal is to list attachments underneath a WooCommerce product, using the tags from that product. Everything works fine if I manually enter the tags at 'product_tag', but when I try to use an array $...
0
votes
2answers
118 views

Sort posts according to date

I have problem with sort posts according to date: My code now: <?php global $switched; $original_blog_id = get_current_blog_id(); // get current blog $blog_ids = array(4,1); foreach( $blog_ids ...
0
votes
1answer
24 views

Unable to render custom field after attempt to generate a list of recent post in page template

When I try to render a list of recent post type either by using WP functions or WP query, I'm not able to render the custom fields that I have to render bit after. The content of box with class feat-...
2
votes
2answers
2k views

Get posts by meta data OR title

I have a working query that calls all my posts that have a certain meta value for one of two meta keys: $term = filter_var( $_GET['term'] ); $query = get_posts( [ 'post_type' => 'some_cpt_name'...
5
votes
2answers
228 views

Delete all posts from WordPress except latest X posts

On a project I require to keep only 10 latest posts on website and auto delete all other posts. So I came up with this function which triggers on post publish/update and I used offset parameter to ...
1
vote
1answer
403 views

Getting movie and serial on actor page

I'm building a cinema site, I came with a problem, let me explain: Movies- are stored in Post's Actors- are stored in Post Type - persoane ( taxonomy= lista) Serials - are stored in Post Type - ...
0
votes
0answers
31 views

Secondary ordering and order DESC not working when using meta_value_num

I have this query: $args_members = array( 'posts_per_page' => -1, 'post_type' => 'team_member', 'post_status' => 'publish', 'meta_key' => ...
0
votes
1answer
87 views

Loading post template that contains a nested loop with ajax

I'm currently working on a project where I'm loading a post with ajax. I'm using get_post() to get the post, setup_postdata() to setup the post data, and get_template_part() to load the template ...
0
votes
3answers
34 views

Order post by taxonomy

I am trying to write a get_posts() query to retrieve 7 posts per page. The retrieval of these posts are based on 3 different tags, "Featured","Highlighted", and "News". Now the "Featured" post take ...
0
votes
2answers
2k 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
45 views

numberposts not responding to wp_reset_postdata()

I am working on a loop where I want the content (from 2 separate categories) to be displayed like this: 1 large format post, 1 random product, 2 small format posts, 1 feature post ...repeat. In order ...
0
votes
1answer
131 views

Why does get_posts only show results for Admins or logged-out users?

I use a get_posts() call with these arguments: array(6) { ["include"]=> string(14) "1633,1634,1635" ["post_status"]=> string(3) "any" ["post_type"]=> string(10) "attachment" [...
0
votes
0answers
33 views

How to search posts by title, id and author? [duplicate]

i am getting the details from a custom search with the below query from a parameter $_REQUEST['search'] in the URL $custom_args = array( 'post_type' => 'post', 'posts_per_page' => 5, ...
0
votes
1answer
26 views

get_posts array 'between' not behaving

if I make the query of $apartments = get_posts( array ( 'post_type' => 'apartment','meta_key' => 'bedrooms','meta_value'=> array(4,12) , 'compare' => 'BETWEEN' , 'type' => '...
1
vote
0answers
67 views

Pagination with an array of post objects?

I am curious, I have the following code: foreach ($this->networkBlogs as $siteBlog) { switch_to_blog($siteBlog['blog_id']); foreach (get_posts() as $postObject) { ...
0
votes
2answers
77 views

This wp_query will not return any posts and only seems to work with post_status inherit?

I'm having difficulty returning a list of posts. This file is contained in a plugin folder (ultimately I want to have a cron job just run the script here to delete posts with invalid urls in the given ...
1
vote
4answers
5k views

Check If posts exist in custom post type category, outside of loop

I'm building a navigation, outside of the main loop, that includes drop downs. I have a custom post type called 'Events', that has its own categories. I would like there to be a drop down if there ...
0
votes
1answer
74 views

Even with PHP plugin get_posts not working in widget area

I have the following code in a template, it and displays images form a custom field: <ul class="about-us-grid"> <li> <?php $posts = get_posts('post_type=employee&orderby=rand&...
0
votes
0answers
63 views

Group by multiple taxonomies and hide empty loops

This was helpful for grouping, but didn't quite solve another issue I'm dealing with: Display category posts grouped by taxonomy I've got two different variables to sort through. 'product_type' and '...
0
votes
0answers
46 views

Querying on a custom post type without tags returns no posts

A theme I'm working on contains a custom post type, "help_question", which is declared as such in functions.php add_action( 'init', 'create_post_type' ); function create_post_type() { ...
0
votes
0answers
38 views

URL rewriting taxonomy term

I'm trying to find solution for the following hours now and i don't know if this is applicable. I have 1 Custom Taxonomy "Years" for Post Type "Post (default)". The taxonomy has 2 Terms: "2014" and "...
0
votes
0answers
165 views

Pre_get_posts meta query value serialized array using multiple URL parameters

Using the 'pre_get_posts' action I'm looking to return all posts which match multiple URL parameters by defining the meta_query. For example: example.com/?size=large,small&options=green,blue,red ...
2
votes
2answers
3k views

WordPress get posts by date without query_posts

I'm want to get posts from the last 30days in a sidebar but I don't want to use query_posts, is there a way to achieve this with the get posts function?
0
votes
2answers
59 views

How to Retrieve Post ID of another page

I have a post and payment page each posts contain a payment form I want to know how I can retrieve the data to I can execute and publish where the post payment came from on payment form submit $...
0
votes
1answer
124 views

How to get the intersection of two terms both from different custom taxonomies

I have a custom post type listing Then there are two custom taxonomies job_listing_region job_listing_category On home page i have links to job_listing_category like shop,eat,stay etc. and job ...
0
votes
1answer
52 views

Get posts in between specific ID's

I want to get the posts from within specific ID's ( 10 - 15 ), just like we do in SQL select * from employees limit 10 , 20 ; I wanna get in this Wordpress posts.
1
vote
2answers
155 views

Display latest x posts from all categories in Custom Post Type/Taxonomy

I am attempting to display the latest x posts from all categories using a custom taxonomy called 'case-studies' in WordPress. I have managed to output all the category names as heading links I have ...
0
votes
1answer
142 views

Mathematical operations on custom field values? (updated)

I'm attempting to write a function, run by a cron schedule at midnight every night, that will subtract 1 from the integer value of a custom field. It will function basically as a countdown timer for ...
1
vote
1answer
116 views

Get posts from specific taxonomy term

I have nhl news website and I have taxonomy for each season (ex 2014-15) Taxonomy in functions: function wptp_register_taxonomy() { register_taxonomy( 'season', 'post', array( ...
3
votes
1answer
242 views

How to order by post_status?

I'm using get_posts() like this: $posts = get_posts(array('orderby' => 'post_status')) which is not possible cause it's not in the allowed keys in the parse_orderby() method How to get around ...
0
votes
2answers
4k views

Wordpress get_posts by category

I have the following bit of code: $args = array( 'posts_per_page' => -1, 'category' => 7, 'orderby' => 'name', 'order' => 'ASC', '...
0
votes
1answer
3k views

Sort get_children by menu_order

I'm using the jQuery Carousel Gallery and unfortunately it's not working with WP's new v3.5 gallery ordering. When the client drags to rearrange images, those changes are not reflected in the front-...
1
vote
1answer
28 views

Modify theme to get page excerpts on front page

I am trying to modify this theme so that the Latest News section shows excerpts from 3 specific pages (for example, /page1, /page2, /page3) instead of 3 most recent posts. This is the relevant code ...
1
vote
1answer
240 views

Display the_content on click jquery

I'm trying to display the_content of a post on click. the problem I'm having is that it display always display the same content. I mean by on click on read for post A, it display the_content of post ...
0
votes
1answer
114 views

Memory issue with get_posts( ) function

I got a fatal error in existing code, when I debug deeper I found that it was coming from bellow line. get_posts( array("posts_per_page"=>-1) ); Can anyone explain why is that and how to ...
2
votes
1answer
4k views

SELECT * FROM $wpdb->posts WHERE ID > 160

I would like to retrieve all posts and relative tag with ID greater than 160. I tried: '$args=array( 'post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => 5, 'orderby'=> ...
0
votes
1answer
75 views

Reset Wordpress Post Query to default

i am in a situation, i am creating a custom wordpress theme but i am stuck over something. in my index/home page, firstly i am displaying 6 posts by category like below <?php $posts = get_posts('...
0
votes
0answers
54 views

Is there a way to sort the results from “get_post_type” alphabetically?

I am trying to generate a list of my custom post types for use in a template. I have successfully managed to output the list, but unfortunately they are in order of creation and i would like them ...
1
vote
0answers
156 views

How to find a post using XML-RPC without knowing ID

I'm using the following function to retrieve individual posts from an external server using the WordPress XML-RPC Post API: public function get_post() {      include("lib/xmlrpc.inc"); ...
0
votes
1answer
81 views

Show excerpt if no title in admin view

Usually my posts do not have a title, so in the admin view it always says "(no title)" wherever the title would be shown. So I am wondering how I could hook into that view function. I would like to ...
1
vote
1answer
207 views

How to remove 'GROUP BY' from SQL query produced from get_posts?

Wordpress, Archive Cateory page. From default WP_Query->get_posts() we are getting something like this: SELECT wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = ...
0
votes
2answers
47 views

get_post orderby not working in plugin

Please take a look at the loops below, I'm having issues trying to order the attachment by title, name, and modified. <?php foreach ($instance['data'] as $id) : ...
0
votes
1answer
241 views

meta_query date and time comparisons

I am trying to query my posts against the value of 2 custom meta_keys... '_mdjm_event_date' formatted as Y-M-D (2015-05-13) '_mdjm_event_finish' formatted as H:i:s (23:35:00) Here is my query... $...
0
votes
1answer
245 views

How to get the current user post and it's ID?

I have a site setup so users can publish a post via the frontend, what happens is, there post is posted as a status, 'Pending Review, in a custom post type. How can i get the post ID for this ...