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)) {
                $rows++;
                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])) {
            $i++;
        } 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?

link|improve this question

79% accept rate
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
feedback

1 Answer

up vote 4 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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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