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
382 views

AJAX pagination offset returns same post on adjacent pages

I have a simple AJAX pagination that seemed to work just fine, calling one Wordpress page (not ideal, I know) with a pagenum and a sort order arguments and it returned 4 custom posts per call. The ...
-1
votes
0answers
11 views

Use Hero Carousel to display featured post carousel [on hold]

I am new to Wordpress Development and I need a few pointers. How can I use Hero Carousel to show featured or latest post in my theme's main page.
1
vote
1answer
330 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
2answers
2k 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
9 views

Display posts from catagories

I am using an option framework. This saves catagory ids.To get ids I have done $cat = $atts['post_catagory']; var_dump($cat); The var dump result is array (size=2) 0 => string '1' ...
0
votes
3answers
1k 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
1answer
2k 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 ...
0
votes
2answers
2k 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
399 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'=> ...
1
vote
1answer
31 views

date_query not returning some posts in date range

I'm getting some very strange results with the date_query parameter of get_posts. I have a post for which: date('Y-m-d H:i', get_post_time('U', false, $postid)) returns: 2014-04-03 10:42 This ...
4
votes
3answers
595 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' => ...
2
votes
2answers
817 views

Serialized array, grab specific posts with meta_key/meta_value[0]->is_featured

I've a postmeta key saved in DB: mediSHOP_product_extras It's value is Unserialized: Array ( [0] => Array ( [is_slider] => 0 [is_featured] => 0 [in_stock] => 0 [video_url] => ...
0
votes
0answers
10 views

Change get_posts to loop.php suitable version

I did't know that get_posts don't work with loop.php. I already have this great loop.php file and I want to use it. I created this code: $pageposts = get_posts( array( 'relation' => ...
0
votes
1answer
16 views

Get images by category

My current way of getting the images for sliders is by using the following code that works perfectly: $args = array( 'post_type' => 'attachment', 'sort_order' => 'ASC', ...
0
votes
1answer
41 views

Need help with get_posts pagination

I've been working on a wordpress site, and I'm trying to build a page where visitors can see all of the images that have been uploaded to the wordpress media gallery, regardless of whether or not said ...
0
votes
1answer
20 views

Multiple posts/pages in one page?

I'm trying to create website with index page which will have 2+ different boxs with different content generated from post or pages in WP administration. This page will be looks like this wireframe. ...
0
votes
1answer
17 views

excluding current post from get_posts

i have this block of code displayed in single.php template <ul class="cat-wrap"> <?php global $post; $categories = get_the_category(); foreach ($categories as ...
0
votes
1answer
16 views

get_posts not pulling the correct number of posts

I am using the BracketPress plugin and trying to pull all of the posts of post_type brackets so I can send a newsletter blast to everyone with their current leaderboard position. However the get_posts ...
-1
votes
3answers
50 views

Custom Post Type meta value is being saved in array, instead of just the string (as value)

So, this is how WordPress is saving my CPT meta: array(8) { ["product_id"]=> array(1) { [0]=> string(10) "abcdefg987" } ["end_date"]=> array(1) { [0]=> string(10) "02-02-2015" } ...
1
vote
2answers
4k views

Using get_posts with arguments found in meta keys

I am using get posts, but I need to refine the query based on posts where a certain meta_key has a certain value. Something like this <?php $reviews = ...
0
votes
0answers
31 views

How To Use get_posts & get_the_post_thumbnail Outside The Loop

This works fine within the loop but i cannot hook it outside the loop. global $post; $args = array( 'post__in' => array( 1, 5, 17, 19, 21, 23, 25, 27, ) ); $thumbnails = get_posts($args); foreach ...
0
votes
1answer
34 views

WordPress - List Sub Categories and Sub-Sub Categories, With Posts

I have the following code. It allows me to show sub categories and documents within them. The thing is, a sub category may contain further sub categories. The code below will show documents belonging ...
80
votes
4answers
54k 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 ...
0
votes
0answers
42 views

Both WP_Query and get_posts returning 1 post

I am having a weird issue. Both WP_Query and get_posts returning only one result, i.e only the latest post. Never faced this before.. The WP_Query: function custom_tsr_query() { $the_query = ...
0
votes
1answer
36 views

Multiple get_posts() queries on one page

I'm building custom page template, which has some content editable through proper articles/posts. Below are those code blocks: <?php $contact = new WP_Query(); $contact = get_posts( array( 'slug' ...
0
votes
0answers
57 views

Trying to use and understand JSON API and get_posts

Me and my friend are breaking our heads to implement something. We are trying to get the results similar to function get_posts from JSON API ...
0
votes
2answers
72 views

How to access $wp_query object from array of posts given by get_posts?

I have a simple custom query driven by get_posts: <ul> <?php $args = array('post_type' => 'event', 'numberposts' => 6 ); $myposts = get_posts( $args ); foreach( $myposts as $post ) : ...
0
votes
1answer
3k views

How to create a “latest news” page showing a list of posts from blog category

I am using the Modest theme from elegant themes at http://lilsaintz.co.nz Under the slider on the homepage, there are three content areas that are generated from pages. I would like to make one of ...
0
votes
1answer
49 views

Function using get_posts() with tax_query not working when called from functions.php

I want to get an array of all the 'bands' in taxonomy 'types', and use the array later on in other functions etc. I have a utilities.php file that I require() in functions.php and it has the following ...
0
votes
0answers
24 views

Fetch posts list from fist CPT taxonomy term and list under 2. CPT

I have two custom post types registered. Custom Post Type: PUBLIKATIONEN with the two custom taxonomies LISTEN and AUTOREN Custom Post Type: AUTOREN Both have archives. With: <?php echo ...
0
votes
2answers
416 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
2answers
74 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 ...
1
vote
0answers
42 views

Conflict with get_posts and the_content

I have this snippet in my header.php to display a slider: <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 6, 'meta_query' ...
1
vote
1answer
55 views

Only showing the_date and the_excerpt for first entry in get_posts

this code below shows the titles and links for 5 posts in get_posts no problem but only displays the date and excerpt for first post... any help please? <?php $args = array( 'posts_per_page' ...
219
votes
6answers
77k 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
2answers
41 views

Fetching All Posts (200+) in a Category - Performance Issues?

I want to get the IDs of the 2 previous and 2 next articles in a certain category to show them as a "related videos" playlist. I know that there are the functions previous_post_link and ...
0
votes
3answers
112 views

Paginate get related post by author function

Is it possible to get this function paged? I've tried to add previous and next links but i'ts not working... function get_related_author_posts() { global $authordata, $post; ...
4
votes
1answer
10k views

get_posts - get all posts by author id

I want to get all posts by certain author id (current user). Later, I want to pick the first post made by this user (ASC). I guess I do not use the right arguments in get_posts, am I? ...
1
vote
1answer
5k views

Sort “get_pages” by menu order not ordering

I'm using this bit of code to generate a page full of items but they won't sort into the menu order, any ideas as to why? <?php $pages = get_pages(array('child_of', 'menu_order')); ?>
0
votes
0answers
11 views

Display Children Category post and child post under it

Hi I need to display only child category post in home page and then its children title under it in home page recent posts . While doing this it displaying category children post too in home page ...
0
votes
2answers
73 views

Get posts by category name

I'm having a terrible time trying to figure this out. I've registered a custom taxonomy (clinical-programs) and like to list all the PAGES that are assigned to particular page(s).
0
votes
2answers
39 views

Display all Post titles with Category and Tag

I am trying to display all posts that are in a specific category and have a specific tag. This is what I have so far but it seems to ignore the & and make it or. <?php $myposts = get_posts( ...
0
votes
1answer
37 views

Get x recent posts by author?

So I have ten authors on my site, and I want to designate a section where it shows the ten authors and their 5 latest posts in the form of the post title linking to the post. I tried using the ...
5
votes
3answers
2k views

Regenerate Slugs From Title of Posts

is it possible to regenerate the slugs programmatically after changing the titles of the post? Numerous post titles were updated and the slug was not updated with the title so I need to regenerate all ...
3
votes
3answers
14k views

get_posts assigned to a specific custom taxonomy term, and not the term's children

Say I have the following taxonomy terms: Term 1 Term 1.1 Term 1.2 Term 2 Term 2.1 How can I get only posts that are assigned to Term 1 and not include those that are assigned to Term 1.1 or ...
0
votes
0answers
24 views

Send POST variable with 'post_publish'

I have a custom button which triggers my page builder to load on the post.php page upon clicking it. However, I want to send a variable as well with it. Here's what I tried $('#post').attr('action', ...
0
votes
1answer
76 views

Get all posts with a certain meta key, except for one with specific title

I need to return all posts with post_test_safe == 1 and exclude one with title ="Special title" Some kind of combined meta query but haven't got anything to work. function getAllPostIdsTest(){ ...
0
votes
1answer
33 views

Worpress url parse

I want to display posts in certain category only with given tag. Problem with parsing url slugs. For example, I have category named 'Clothes': example.com/clothes/ I can get posts in this category ...
1
vote
3answers
462 views

WP Query post meta value

I'm trying to get posts which have applied the meta value trainees. $args = array( 'posts_per_page' => -1, 'orderby' => 'post_date', 'order' => 'DESC', ...
0
votes
2answers
8k views

How to display posts by current user/author in a custom page template?

I am a trying to create a dashboard like custom page template that list post of of the current logged in user. I've tried to find a solution on the net. but none were appropriate