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
0answers
346 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
45 views

Trying to combine a variable together

So I am not 100% sure if the is feasible so hopefully some one can point me in the appropriate direction. I am using the Advanced Custom Fields plugin and on my custom page template I am using the ...
4
votes
2answers
478 views

How to get current post ID in quick edit callback

This question is related to another previously asked question, which is a follow up on an answer. Task As I want to extend QuickEdit to be something really awesome (and more than just quick edit), I ...
0
votes
1answer
101 views

Retreive tags from attached post for media on page

I am working on a custom template file that pulls all images in my Media Library with a specific tag. I was able to get this working with some help from the community, it also shows the title of the ...
0
votes
1answer
366 views

Get title of post image is attached to

So I found this post: Find the post an attachment is attached to and implemented Chip's suggestion but having a weird outcome. I am trying to pull the title of the post that the specific image is ...
0
votes
1answer
239 views

get comments and get posts in loop

I need to get posts done by specific users and get also comments done to these posts, so far I can get the posts and comments but can't get how to do it in loop properly, because now I get the same ...
-3
votes
1answer
188 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?
0
votes
1answer
56 views

How to show only 1 post from a specific category on the front-page

On my front-page i have a 3 col block section below the fold. The final and third column is an excerpt of the most recent post from my art category blog, hopefully this is clear up until here in terms ...
0
votes
0answers
185 views

get posts with hierarchy and all post meta

I created a custom post type to act as a Family Tree. There are currently 40+ post-meta fields that collect all of the important information. Wordpress's built in "parent" function is used to assign ...
0
votes
2answers
242 views

Add Filter not working with get_posts

While tweaking the "Bryans Childpage Thumbnail Generator" plugin, I am applying filter (with pagination) to the get_posts for WP Pages (post_type=page), but its not filtering at all. Here is the code: ...
0
votes
2answers
97 views

Transient Loop Not working as expected

So I created a transient object that used get_posts() to get a series of posts based on some argument. Well the transient was stored - it was created - YAY - now I tried to write this loop: public ...
0
votes
0answers
100 views

show/hide attachments

Is there a way to show/hide attachments in my case images on a post. What I want is to mark an image as "hidden" and then only show it to the admin and hide hidden images from a normal user I know ...
0
votes
1answer
778 views

Need some help with “the_widget()” function

I am trying to create code to display certain default WordPress widgets on my e-commerce site. I have 6 content boxes which display WordPress widgets: • Pages • Latest Posts • Archive (last ...
0
votes
1answer
56 views

Query for draft or scheduled post

What should be the query for checking if there is any draft or scheduled post, I'm not able to make which arguments to take. Thanks
0
votes
0answers
108 views

WordPress multisite post clone

I have 2 theme on my wordpress multi-site, its a property site. One theme is general and another is map theme. Now my platform users are placing property from general (site1) and I want to show them ...
0
votes
2answers
454 views

use get_posts to get custom field data, but in one array

I've run a get_posts query in WordPress and need to pull a pair of custom fields and get all of them into one array. The get_posts query provides an array of posts, but when I use foreach to access ...
0
votes
3answers
391 views

Get only used meta_values

this is how I'm getting the meta values: $apart_locations = $wpdb->get_col( "SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = 'postal_location' ORDER BY meta_value ASC" ); This is how ...
0
votes
1answer
421 views

What's the difference between “get_posts” and “wp_get_recent_posts” when used with “setup_postdata”?

This might be a completely "I'm still new to WP" type question, but I ran into some interesting output when using get_posts() and wp_get_recent_posts() in a custom function I wrote with ...
0
votes
1answer
42 views

Is there a way to target only images within the loop?

I'm new to WordPress and I'm trying to target specific parts of the content. I understand how to grab the title with get_title() — is there something similar for images?
1
vote
2answers
2k views

how to get specific page content

bellow is my code working nice but problem is don't coming with html tag.. like etc... no idea why... <?php $recent = new WP_Query("page_id=2"); while($recent->have_posts()) : ...
1
vote
1answer
131 views

Get mixed category random posts

I have 3 categories: A, B, C. A is having around 1000 posts, B has around 300 posts and C has 50 posts. When I query for 5 posts, ordered randomly. I get mostly posts from A category. How can get ...
0
votes
1answer
231 views

Custom Post Type children and grand-children in one list

So, here is the story: i made a product catalogue with 3 custom post types: - Product - Filegroup (Child of Product) - File (Child of Filegroup) When on product page it should show a ...
2
votes
1answer
5k 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
votes
1answer
169 views

Multisite pagination with get_posts

I'm looking for a way to paginate my get_posts : $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'posts_per_page' => 5, ...
0
votes
0answers
55 views

How do I paginate posts page with $wpdb?

I am using this to get the posts: (...) if ( empty( $categories_defined) ) { $posts = get_posts($args); } else { global $wpdb; $posts = $wpdb->get_results( $wpdb->prepare( "SELECT * ...
0
votes
2answers
74 views

How to get posts and comments amount per hour, per year and per month?

I have this snippet: function count_user_comments_today( $uid ){ global $wpdb; $today = date('Y-m-d'); $tomorrow = date('Y-m-d', time() + 86400); $count = $wpdb->get_var( ...
0
votes
2answers
538 views

Use post__in and post__not_in together?

I'm trying to only show posts that a user hasn't seen, like this: $exclude = array(1,2,3); $include = array(3,4,5); $args = array( 'post_type' => 'post', 'post_status' => ...
0
votes
1answer
970 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
4answers
1k views

how to return only custom 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', ...
1
vote
2answers
127 views

Wordpress not opening posts with only numbers if permalink is post_name

Someone knows why this happens? For instance, I have a post called 1987, but it does not open it when I click on the link. When I use a different permalink structure, it opens it. Why is this and how ...
0
votes
1answer
292 views

If post does not exist, do something

Is this possible? If so, how? I am linking to a non-existing post/page where I get a 404 error. I want to have it to get the url of the non-existing post and make it a link on my 404 page, but I ...
0
votes
2answers
74 views

4 posts per page from single category

I've been trying to display posts that I've categorized as "news-categories". My goal is to only display 4 posts on sidebar of "cbs-news" slug underneath "news-categories" category. By below mention ...
1
vote
1answer
350 views

Using get_posts() with tax_query parameter set isn't working with attachments

I'm working on a project that requires searching for attachments with a given taxonomy-slug pair (in this case, category=javascript). I'm using get_posts() with tax_query set to achieve this, but it ...
0
votes
1answer
118 views

get_posts includes “auto drafts”?

I'm using get_posts to generate a list of posts. $args = array( 'post_type' => 'post', 'numberposts' => -1, 'post_status' => array('publish'), 'orderby' ...
0
votes
2answers
181 views

Function to grab specific image IDs from media library.

I want to grab images 161 thru 166 without having to calling my entire media library array and having to splice those up. In time, the more I have in there the more it's going to slow my site down. ...
0
votes
0answers
291 views

Show all posts using the template page and the loop?

I am trying to make a template page that would display all posts from all categories, in short - every post added to my website. I was googling around and found out that it can be done by using The ...
0
votes
2answers
72 views

While loop articles - if statement order

I want to show a list of articles, but I want to show in the 1st place my second article and after it the last. Eg: Article 1 Article 2 Article 3 Article 4 to be: Article 2 Article 1 Article 3 ...
0
votes
2answers
261 views

Use WP_Query or query_posts() or get_posts() for optimizing a site?

I have read other answers, but I don't understand which is more fast (the best and simple for slow server running)? I have a website with over 1 000 000 hits /day and a slow server with limitations ...
0
votes
1answer
96 views

get_posts always returning the same number of posts = 5

I don't understand why the code below is always displaying the same number of returned post = 5. When I change the $variable value to another post id of a post with an author with another author_id, I ...
0
votes
2answers
156 views

Modified home page query does not yield expected results

Yesterday i asked how it would be best to load all existing pages and their content on front page - to create single page layout. (Single page theme) From the info on that page i created my own ...
0
votes
2answers
232 views

how could I get the pagination as I want to when query posts using get_posts function

I am using WP3.5, and I have a post_list.php which will show all the posts order by post date DESC. Everything is ok except pagination. I have 15 posts, for test purpose, I want to every page show 2 ...
0
votes
1answer
302 views

Trying to check and see if a post has a featured image outside of the main loop

I've got a situation where I need to find out if the currently loaded post has a featured image, if it does, I want it to display a different logo than if it doesn't have a featured image associated ...
0
votes
1answer
72 views

“paged” in WP_Query returns 0 posts

If i don't supply a paged value (get the first page), it works. But when i try to get the next page by doing paged => 2 it doesn't find anything even though there are plenty of posts to get. ...
0
votes
1answer
152 views

Getting URL Variables with a Rewritten Page (Login Page)

As part of a larger project, I am attempting all login activity to occur at the following address: www.url.com/login So, a link that should lead to a form that would allow a user to reset their ...
0
votes
1answer
115 views

Get posts from 2 different categories

I have a custom post (it's called "ait-dir-items") and 2 categories there. On category archive page, I need to get posts which belong to 2 categories. get posts from 2 categories Codition. ...
0
votes
0answers
109 views

get_posts() and 'posts_per_page' arg

$args = array( 'posts_per_page'=> -1, 'post_type' => 'listing', 'meta_query' => array( array( 'key' => 'ListingRid', 'value' ...
0
votes
2answers
245 views

get posts from 2 categories. (2 posts)

I have a custom post (it's called "items") and 2 categories there. 1. on category page, I need to get posts which belong to 2 categories. get posts from category1="Food" and category2="featured" How ...
0
votes
1answer
92 views

get_the_title outputs title until spacing; it does not get full length of title

If I have a post with a spacing in it (like: Hello World), than get_the_title shows me only "Hello" as a link and not the whole permalink. I already tried using a substring to get it done, but it did ...
0
votes
1answer
132 views

How to get all post titles starting with numbers and symbols?

I want to get all posts which are starting with a number (0-9) or symbols, in a list. I managed to get it work for letters, but this one is harder for me. Can someone help me out please? I tried ...
1
vote
1answer
103 views

get_posts - find out if querystring was crap and fallback is used

If we pass a String to functions like get_posts, and that string is not a meaningful querystring (for Example get_posts(' ')), the function returns the results of the default query (the last five ...