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
51 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
230 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
653 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
81 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
97 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
102 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
43 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 ...
5
votes
1answer
958 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
156 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
91 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
179 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
460 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
26 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
412 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
43 views

How to count RSS posts from a custom URL?

In my RSS feed, for example in a custom conditional URL: domain/?m=20130407&feed=rss2&cat=3 I'm getting all my required tags, after editing wp-includes' file feed-rss2.php With pagination ...
0
votes
0answers
90 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
1k 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 ...
0
votes
0answers
249 views

Showing sticky posts with get_posts()

I'm using this to retrieve posts on my index page: <?php $posts = get_posts( "category=13&numberposts=2" ); ?> <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : ...
0
votes
1answer
241 views

Show the title of the latest post by author

I have the following function which I use to show the author name,author avatar and the author biography in a div. I need to show the title of the latest post by the author along with this. Can anyone ...
1
vote
1answer
339 views

Custom Loop, Match Category with Page: How to display post featured image?

I found this answer. It saved my day, but could you tell me how to display featured image of the post with the following code? When I'm using <?php echo $cpost->post_thumbnail('thumbnail', ...
0
votes
1answer
62 views

Show posts in a list separated by day

I want to display posts on index page within a links-list, with only the titles, till now i did the job, but now i want to have space between titles and be separated by day. Please check wimp.com ...
1
vote
1answer
397 views

If meta key exists in get posts function otherwise create it

The following code fetches posts with the meta key home telephone numbers. $metas = ''; $args = array( 'numberposts' => 1, 'post_type' => 'electors', 'orderby' => ...
1
vote
1answer
173 views

Limit popular posts by days

I am using this get_posts array to retrieve top 15 popular posts by comments. The problem is that it shows those all those highly commented posts from the day posts were added into blog. So, the list ...
1
vote
0answers
317 views

get_posts() with pagination problem

<ul class="list"> <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array( 'category' => '8', 'orderby' => 'post_date', ...
1
vote
0answers
45 views

Query Problem in getting top viewed posts

I wanted to display top viewed posts by month, I add this code snip, to form a query and get required 15 posts, but it displays 3-4 posts.Here is my query: global $post; $args = array( ...
0
votes
1answer
188 views

Query specific number of posts for each post type in specific order

This is related to this other question, I tried with get_posts, pre_get_posts, WP_Query and basically every option I could find for 2 days now, no solution yet. The full problem in hand: I have 2 ...
0
votes
1answer
54 views

Specify strict 'order by' in WordPress query

I have a custom post type called Employees where an employee's name is the post_title of each post. I am trying to figure out how I would sort the post_title column by last name. So for instance, if ...
0
votes
1answer
169 views

Get_Posts, only if in both categories

get_posts('numberposts=5&category=93+85')get_posts('numberposts=5&category=9385') Is there a way to have get_posts grab only posts that are in BOTH categories, as above?
0
votes
2answers
240 views

How to query for a page, get data, then query for child pages of that page

Basically, I want to query PARENT for a bunch of custom field data and echo it out. Then, I want to query all of the CHILD pages of that parent and echo out more data. What's the best way to do it? ...
1
vote
1answer
7k views

How to show related posts by category

In my gallery site i want to show other pictures under the current picture (in single post). I seen more codes but it i asks to specify the category, but i dont want want specify the category manually ...
0
votes
2answers
393 views

get_post_custom_values not working

I have made a custom template to show the posts in "Products" category in a single page.I have some custom fields.I need to show the values of the custom fields in the page. I have used the ...
0
votes
1answer
166 views

how to display all images from their siblings/ from same parent?

I need to know how to display all images from the current page siblings. for eg. I got two parents (Hockey and football) with children. In all this children I got one or several images attached (I've ...
0
votes
1answer
195 views

Conditional get template part

My index page look like this... <div id="ad-id">google ad code goes here </div><br /> <div id="post-id">My posts are goes here</div> I use ...
1
vote
1answer
2k views

query_posts() vs get_posts() multiple loops [duplicate]

I have a template which initially had one single loop and it was using query_posts, I added 2 more loops using the same method, However after reading allot about these it was concluded that I shall ...
0
votes
1answer
43 views

Posts being viewed

I am looking for a way to list posts being viewed but I can't find anything online. Is it even possible? I've seen some websites that have these loops, "What other readers are currently reading". ...
1
vote
1answer
2k 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
3answers
1k 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
30 views

How to retrive the text : No movie by this actor

Hy, im building a cinema site, in movie page i have a Custom Field that link's the actor page, when i add a movie and i link the actor, on the actor page i get the movie, now the problem is how can i ...
0
votes
2answers
268 views

Working with get_posts parameters/arrays/strings

I'm transitioning all my query_posts queries to get_posts after a lot of research about how bad it is for performance. My solution is get_posts but working with it is confusing me. Here is what I ...
2
votes
2answers
727 views

Why can I not use setup_postdata($post) in the sidebar?

I have created a function that takes one parameter - post type, and will output each posts with some html and title, content etc within that. However, I want to be able to use functions associated ...
2
votes
2answers
789 views

Why Does get_posts() Return an Empty Set?

I'm writing a custom plugin that is initialized at init. This plugin is trying to query for some custom post types already stored in the DB. Here's my code: $args = array() $myposts = get_posts( ...
1
vote
2answers
49 views

is there a better way of combining this?

Hoping someone can point me in the direction of writing this in a more succinct way. I'm working on my website, and want to display a total of 5 posts from the category 'general wonderings'. The ...
0
votes
1answer
384 views

Combine query_posts() and get_posts() into single query

I am creating a site which uses normal posts for a blog and the a custom post type for events(generated by the events plugin). I have successfuly used different queries to grab both but I want to ...
0
votes
1answer
105 views

Getting post by specific date in Advance Custom Field

How can i get movies there are today in cinema, for example my code display the movies in time that shoud apear 16 January,17 January..., how can i display only the movies in this day. Ex: today is ...
1
vote
1answer
186 views

get_posts in meta box dropdown not showing latest posts

I’ve got a metabox I set up using WPAlchemy that allows authors to add a link to an associated post. It’s been working fine for months but now for some reason the dropdown with the appropriate posts ...
0
votes
1answer
189 views

List random posts on single page in the current category

I would like to show 8 random posts on single page from same category. <?php global $post; $categories = get_the_category(); foreach ($categories as $category) : $args = array( ...
0
votes
2answers
530 views

What should I use, get_posts or wp_query for less CPU load?

I have a blog and on the main page are 3 blocks of posts. So, I get these posts with "get_post" and I have 3 similar codes on page: global $post; $args = array( ... ); $myposts = get_posts( $args ); ...
0
votes
1answer
869 views

Use of caller_ get_ posts

For what purpose following parameter is used caller_get_posts