• to call any random posts that I have created in the past I have teh following code:

    <?php
    global $wpdb;
    $numposts = 5;
    
    $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);
    ?>

    This basically calls 5 posts that has the active status of a post. but it also pulls pages, because it is posted as publish in the DB. if I am saying it right. what I want to do is call all the published posts and not pages. what can I do to edit this?

    I was unable to find a good plugin, and since I have this already in my blog and several sites I figure there has to a small line of code change to pull only posts and ignore pages.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Add this:

    post_type = 'post'

    Result:

    $rand_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY RAND() LIMIT $numposts");

    Thread Starter ianternet

    (@ianternet)

    ahh damn duh! something so simple, makes sense! thanks a lot ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Random Post but IGNORE Pages’ is closed to new replies.