0

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?

1
  • 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, 2011 at 10:20

1 Answer 1

8
$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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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