WordPress.org

Ready to get started?Download WordPress

Forums

Random posts with content (2 posts)

  1. Tri-Fusion
    Member
    Posted 7 years ago #

    Hi,

    I want to show 5 random posts exactly as the posts that display on the index page, which includes title and content. Some other random posts plugin only able to show title

    thanks

  2. Tri-Fusion
    Member
    Posted 7 years ago #

    this code works but it shows the pages as well. Is there a way to omit the pages?

    <?php
    global $wpdb;
    $numposts = 10;

    $rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY RAND() LIMIT $numposts");
    foreach($rand_posts as $post) :
    setup_postdata($post);
    ?>

    ...

    <?php endforeach; ?>

Topic Closed

This topic has been closed to new replies.

About this Topic