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
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 ...
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
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 ...
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
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
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
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 ...
4
votes
5answers
4k views

How to return results of a get_posts() in explicitly defined order

I'm trying to create a loop of explicity ordered posts, for example: <?php $args = array( 'include' => '1,3,8,4,12' ); ?> <?php get_posts( $args ); ?> The results are ...
0
votes
2answers
536 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
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
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
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
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
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
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 ...
0
votes
1answer
2k views

get_posts by id not working

I have the following code: global $post; $current_post = $post->ID; $array=range(1,$current_post); $posts = get_posts('numberposts=5&post__in=' . $array . '&category='. ...
0
votes
2answers
474 views

Can't sort get_posts by post_mime_type

I'm trying to run a query to get all attachments and I'd like to sort by the post mime type. This query isn't working. Any ideas? $query_args = array( 'post_type' => 'attachment', 'numberposts' ...
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
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
108 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
2answers
612 views

Count number of posts of current month

I am trying to echo the number of posts for the current month from all categories but it isnt working. <?php $month = date('m'); $year = date('Y'); $countposts = ...
0
votes
2answers
380 views

Don't submit post if post title exists

I am using the User Submitted Posts plugin which I love. The only problem with this plugin is that it does not check for duplicate post titles and outputs a post with the same title, even if it ...
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 ...
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 ...
0
votes
3answers
76 views

Wordpress ultra slow if I click on posts?

I have 5000 posts on my website, which I have uploaded from a CSV file. This all went well and the website is fast on the back-end and frankly on any other page. There is one exception: if I click on ...
0
votes
3answers
310 views

shortcode for recent custom type post

I'm not a coder so I may have done some "coding" crimes, apologies. I've bought a theme who has shortcodes for last posts but not for last "custom post type". So I tried to create last "custom post ...
0
votes
1answer
62 views

Turn get_posts as string into an array for use in theme admin options

I am trying to add a drop down list of all posts into a theme admin section...without forklifting the theme code. I need to pass the post title and id into the 'options'=>array() like so: ...
-2
votes
1answer
255 views

Related Posts Without Plugin And get_posts( $args ) ?

Is there a simple way to get related posts without having to use a plugin? I am preferably looking for something really simple like a couple lines at most I currently use this to get random posts, ...
0
votes
1answer
997 views

Advanced Custom Fields: Post Object - Not returning data [closed]

I have a custom post type called "Training" with an archive page (archive-training.php). I have another custom post type called "Courses". I am using Advanced Custom Fields: Post Object to link ...
0
votes
1answer
88 views

Internal linking to posts permalink fail because of spaces and stripe at postname

I have written a function which outputs a tag in a textarea in which people can link internally to other posts on the website. This works like a charm except with using a postname permalink ...
0
votes
1answer
118 views

get_posts() doesn't consider user permissions

I want to show a list of links to posts for the logged in user on my wp. So I started to do so: $posts_array = get_posts( array( 'post_type' => 'download', 'post_status' => 'publish' ) ); ...
0
votes
1answer
124 views

Bulk Attach Or Insert Media To Post Without Opening Post Editor

How to create a custom panel inside wp admin dashboard where we can insert media to specified posts in bulk? Here is the illustration: As shown on the image above, it list all available media on ...
0
votes
1answer
44 views

Display Posts with template on a Page

OK, I'm sure some WP pros here will think this is a dumb question, and I'll probably get some flak, but I have actually read plenty of documentation, and I just don't think I'm even going in the right ...
6
votes
1answer
2k views

What does setup_postdata ($post ) do?

The codex defines it as 'Set up global post data. Helps to format custom query results for using Template tags.' I don't really understand this. Here is a code example : global $post; $args = ...
0
votes
1answer
3k views

Count posts returned by get_posts in external PHP script

I'm using WP from an external PHP script by including the wp-load.php file. All functions and everything works as expected so far, except one thing: I can't get the $wp_query->found_posts to work ...
0
votes
1answer
163 views

Efficiently loop over huge number of posts

I want to loop all posts to do some processing, but one of my concern is there are many posts and it might used up my memory, so I want to loop posts with offset, something like paging. e.g. $posts ...
1
vote
2answers
92 views

How do you Query posts with nothing in common?

We can get multiple posts manually in a page, but that's generated in a template, AFTER the default query returned something else (page/post, etc) How do you query multiple posts in a public query, ...
0
votes
1answer
247 views

get_posts post title permalink not working for last item in array

I have a custom field attatched to a post that contains the following array of post titles... a:6:{i:0;s:21:"Strawberry Cheesecake";i:1;s:15:"Flapjack";i:2;s:14:"Chocolate Muffin";i:3;s:27:"Apple ...
1
vote
1answer
597 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
1answer
28 views

Number of displayed posts

I have tried many things to solve this problem. So I have a plugin which displays projects assigned to users in a widget. It displays projects as posts. The problem is that it only displays 5 ...
3
votes
3answers
3k views

get_children() Not Working with orderby Parameter

I am trying to use the orderby parameter in the get_children function as below: $navigation = get_children(array( 'post_parent' => $parent->ID, 'orderby' => 'menu_order' )); But it is ...
0
votes
1answer
427 views

Retrieve Image Attachments Getting Post Thumbnail Image First

I have written a funtion to get post image attachments, is there any way of ordering these images such that the first is always the post_thumbnail? Code below Thanks John function ...
0
votes
0answers
122 views

get_pages not returning any results or error when get_posts works

I have a code sample that works with get_posts but I now need do with get_pages so I can get grandchildren in the results set: $attachments = get_posts( array( 'post_type' => 'attachment' ...
0
votes
1answer
2k views

tax_query in get_posts() not working?

I'm trying to print out all the posts within every taxonomy for a custom post type called product (jigoshop products). So i get all of the taxonomies using $cats = get_terms('product_cat');, then i ...