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

Get posts in archive page

I am using this code to show posts in columns. How can I set this part ('cat=3&numberposts=5&offset=0') as so archive page should automatically get posts from clicked catagory? <div ...
1
vote
2answers
762 views

Only retrieve posts where post_excerpt has been filled out

I'm trying to use get_posts to only return posts that have an excerpt. Done lots of searching and have been trying to use "posts_where" filter on the query but my SQL is lacking. This is what I'm ...
1
vote
1answer
1k views

how to exclude “featured” posts from the main loop?

In a category.php template, I built a function that lists "featured" posts before the main loop. The featured posts are selected using a custom field and get_posts(): function ...
2
votes
2answers
519 views

get selected post using $_GET

im trying to get a post info when I click a button on the post and make it echo out the the same info it has in the else function, I tried adding in a query but in return it makes it echo back all the ...
3
votes
4answers
8k views

setup_postdata() does not seem to be working?

I am not sure why but I have used get_posts() to query for some data. Then I used setup_postdata() ... I think its used so that I can use functions like the_permalink() etc with the new post data? ...
0
votes
1answer
3k views

Can I use numberposts=-1 and offset together when using get_posts()?

I'm currently using get_posts() for a little part of a theme I'm working on. However, I've run into one little hiccup. If I want to show all posts for a category, I set the 'numberposts' argument to ...
0
votes
1answer
896 views

get all categories' latest post in one query

My WP blog has 12 categories, 80 subcategories. I need to fetch the latest post from each of those 12 categories. I know how to do it in 12 queries using 12 get_posts() but is there a way to get ...
1
vote
1answer
1k views

Exclude Current Post from Recent Posts Loop

what would be the best way to exclude the current post I am viewing from this recent posts query. Thank You! <?php global $post; if (in_category('top-lists')) { ...
0
votes
2answers
3k views

exclude category from get_posts?

getting posts by cat with get_posts but need to exclude another cat called london or id 10. is this possible? best, Dc. // array(7,-10) $laargsM = array('category' => 7, ...
0
votes
1answer
1k views

Get the ID of the latest post

Been all over looking for the best way to do this. I want to get the ID of the latest post of a certain post_type. How can I do this in the cheapest way possible (by cheapest I mean using the least ...
3
votes
3answers
9k 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
1answer
1k views

Paging result of get_posts in function

I have created a function to use as a shortcode to allow me to display a specific post type on my page. The function works well, but I would like to the results to be paged, and the navigation only to ...
1
vote
2answers
1k views

functions.php conditional tag only for custom post type

I'm using gpp slideshow, which overwrites wordpress's default gallery display. I only want to use it on my custom post type, "listings" - how would I reference it to only replace wordpress's default ...
1
vote
2answers
299 views

making random query button using $_GET

Im trying to make my post random when i lick on my button using $_GET but it just keeps refreshing my page instead of refreshing with the random post. <a href="<?php echo $my_query; ...
0
votes
1answer
2k views

Newbie Question: 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
743 views

List one post only from each subcategory using get_posts?

Custom Post Type = 'projects' with a Hierarchical Taxonomy = 'projects_category' projects - big-corporates -- company one ---- first project 1 ---- second project 1 ---- third project 1 -- company ...
1
vote
1answer
507 views

get post attachment using ajax

I'm developing a plugin and I'm trying to get the url's from a post's attachments with ajax. If the user is on a single.php page. After some seconds, I'm sending an Ajax request, getting all the ...
0
votes
1answer
505 views

post__in not taking my list of IDs

I have a Custom Field on a page named banner_id_list. I have a Custom Post Type called top_banner. I add a few banners, note the IDs and then go back to the page and add a comma delimited list of IDs ...
0
votes
2answers
378 views

How to query the latest 5 posts and sort them by title?

I'm looking to draw a menu listing of the latest "n" number posts, where the number "n" will be a user defined setting stored as an option. n = 5; //Pull the latest 5 posts from the database. The ...
0
votes
2answers
2k views

How Can i Get 5 Recent Post Title With Corresponding Link?

I Want to Add My Latest 5 Post Title with Corresponding Link in My Header Position.What was the Actual Php code?Am Newbie ....
1
vote
2answers
1k views

Trying to only display 1 category using get_posts

I'm trying to only display posts from a certain category in a widget. I've tried it in a few different ways but it is still showing posts from all categories. Here's my code at the moment: $posts = ...
1
vote
1answer
697 views

Automatically republish old posts

been seaching on google for a plugin for this and can't seem to find anything realiable. The only plugin I found is called "old post promoter". Any ideeas? Can this be done with googl old fashion ...
1
vote
1answer
4k 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')); ?>
5
votes
1answer
523 views

How to organize and cache additional data associated with terms?

I'm updating a plugin of mine and am have a hard time figuring out the "best way" to build in a specific bit of functionality. The plugin allows users to associate images from their media library to ...
1
vote
1answer
938 views

Adding Pagination on a Custom Author Page

i have created a custom author's page that list the title of their posts. but the problem is i can't get the pagination to work if it's beyond the set post per page value. i have used get_posts() to ...
0
votes
1answer
140 views

Not able to get random post

I want to display a single random post out of the 5 latest posts in the category 'news'. The approach I'm using is this: // Custom function to retrieve catgory ID by category name. $cat = ...
0
votes
1answer
358 views

How to query custom post types with multiple keys?

I recently upgraded WordPress from 3.0.x to 3.1.2. I had set it up to use custom post types before the upgrade. I need make a list of events that are occurring that started in the past until they ...
0
votes
1answer
4k views

How to get The Loop working with $wpdb->get_results()

I am doing a rather complicated custom query on a blog's front page, and trying to show the results using The Loop as shown here: Displaying posts using a custom SELECT query The query filters posts ...
1
vote
2answers
5k views

Does meta_query work within get_posts array?

I can't seem to get this to work — I'm trying to show posts that have the meta 'featured_image' value set to anything. From what I can tell, it's set up correctly, but I'm in a little over my head. ...
0
votes
2answers
116 views

WordPress echoing content in seemingly random place

I have been building a series of theme pages. On one page a users messages (post_type=messages) come in in a tab on the page. The content is displayed in place as is the title etc.... The content is ...
0
votes
1answer
94 views

Number of posts in the archive

How do I show 10 posts on the first page of the archive, and 20 on others (>1)? My custom post type name is "apartments". Cheers!
2
votes
1answer
2k views

meta_query: using BETWEEN with floats and/or casting to DECIMAL

Each post has a lat/lng value attached to it via postmeta. I'm trying to grab all posts within a bounding lat/lng value. Here's the get_posts query: $posts = get_posts(array( 'posts_per_page' ...
1
vote
2answers
793 views

get_posts from post x(offset=>x) to end

How can i get the posts using get_posts from let's say post 10 and beyond?So if i have 200 posts i will get from post 10 to post 200(190 posts)? Because as i see if i use <?php $args = array( ...
0
votes
1answer
324 views

Prioritising and Ordering Posts By Category Name Using A Custom Loop

I have a custom loop pulling out videos all assigned to various categories. However there is a category called "new-video" and I need to pull out all videos using my custom loop, but I would like the ...
0
votes
1answer
3k views

Getting only a specific post type with get_post?

I'm using the following function to get some posts based on their vote (Vote it Up plugin): function top_voted($number){ $a = SortVotes(); echo '<div class="voted">'; $rows = 0; ...
0
votes
1answer
843 views

Function to get content by ID

I'm trying to get text only content of posts by ID. I modified this function as follows, but at the moment it returns nothing. I cannot see what's wrong with it. function get_the_excerpt_id($post_id) ...
2
votes
1answer
1k views

With get_posts(), how can I put a category as a variable

I'm a noob at this so please bear with me. I have the following code to return post title as links within categoryID 6, which is working fine: <?php global $post; $cat_posts = ...
1
vote
1answer
5k views

Query Posts or Get Posts by custom fields, possible?

If I were to take a standard query post. <?php query_posts('post_type=payment'); while (have_posts()) : the_post();?> Only this time I would like to query the post by 2 custom fields that it ...
0
votes
1answer
340 views

If clauses in get_posts query

I am using the get_posts tag to get 4 random posts from a custom post type. However, I only want to get a post IF it has the $pic_url set. I´ve tried using... if(!$pic_url) {continue;} But that ...
0
votes
1answer
139 views

Page displays content from different query?

How can I reset all variables in order to get the actual page content? I keep getting the last post's content I've called from a news-box I've implemented - but need the actual page's content .. ...
2
votes
1answer
3k views

Whats the way to format a date after using get_posts()

I see that theres no way to get a formatted date from a function like echo get_the_date($post->ID, 'd M Y'); get_the_date only works with the current $post. If I used get_posts() how can I ...
0
votes
2answers
1k views

Am I using get_posts wrong?

I have <?php $folioPosts = get_posts(array('category_name' => 'portfolio', 'numberposts' => 3)); if ($folioPosts->have_posts()) : foreach ($folioPosts as $folioPost) : ...
0
votes
1answer
1k views

What's wrong with this post__not_in argument?

In the script below, the post__not_in argument does not appear to be working unless I hardcode the post ids inside the array(). Anything stand out? If an item is in the category, but also in the ...
0
votes
1answer
423 views

Custom query for custom post_type

I need to display a list of current tasks. Each task has a custom post_type and a start date and end date. Can someone tell me how to modify my query so it will pick up any tasks that have a start ...
3
votes
1answer
2k views

Is it better practice to use query_posts, WP_Query, or get_posts to create various custom loops within a Page?

Right now, I'm using get_posts to retrieve cusstom posts types with a custom taxonomy assigned to it in order to generate static content like this: <?php /** * Template Name: Front Page * ...
4
votes
1answer
5k views

Why get_posts are only showing five posts (retrieved by assigning a category to them?

Here is the link http://www.brianfunshine.com/voice-work/voice-page/ This is the code: <?php /** * Template Name: Voice Page (Two Columns) * @package WordPress * @subpackage Twenty_Ten * ...
1
vote
1answer
2k views

Different Results with query('s=computer') vs get_posts('s=computer')?

I have two different pieces of code and it's returning two different results. $search_query = new WP_Query(); $search_posts = $search_query->query('s=computer'); echo count($search_posts); vs. ...
5
votes
3answers
3k views

Getting the Intersection of Two Custom Taxonomy Terms for a Custom Post Type?

(Moderators note: Was originally titled "How to get_posts of a custom post type that is in two custom taxonomies?") I have a custom post type that has two taxonomies which are separate, one called ...
3
votes
1answer
5k views

Get term SLUG by term ID

I have a hierarchical taxonomy called 'tarefa' I have to display all posts from a child taxonomy. I used get_term_children function function to verify if the taxonomy parent has children. If the ...
4
votes
2answers
240 views

Show the First Post from Each of 3 Different Post Types on a Web Page?

I have 3 different custom post types: 1.) "events", 2.) "winners" and 3.) "offers". How would I go about retrieving the first (latest) post in each of these post types on a single web page (i.e a home ...