WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
    //Now do not include deleted posts
    $i = 0;
    while ($rows < $number) {
        if ($a[0][$i][0] != '') {
                $postdat = get_post($a[0][$i][0]);
            if (!empty($postdat)) {
                echo '<div class="fore">';
                echo '<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">'.$a[1][$i][0].' </div><div><a href="'.$postdat->guid.'" title="'.$postdat->post_title.'">'.$postdat->post_title.'</a></div>';
                echo '<div class="votecount" style="width: 1em; color: #555555; font-weight: bold;">'.$a[1][$i][0].' </div><div>'.$postdat->post_content.'</div>';
                echo '</div>';
        if ($i < count($a[0])) {
        } else {
            break; //exit the loop
    echo '</div>';

I would like to only get the posts of a certain post type. I think I have to do something with get_post but I'm not familiar with it.

Any suggestions?

share|improve this question
I see you asking a lot of Qs. So i'd please you to show us a simplified example with meaningful vars and explained function calls. thanks. – kaiser Mar 25 '11 at 10:20
up vote 5 down vote accepted
$the_posts = get_posts(array('post_type' => 'post_type_name'));

That will get all posts from the post type called "post_type_name" so replace that with whatever custom post type you are using. I mean this in the nicest possible way, but you should probably read the documentation as this is a pretty well documented feature that isn't too hard to understand.

Documentation for get_posts is available here on the Wordpress website with plenty of example code for you to easily understand.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.