Support » Plugins » database query for random posts

  • I have a query that pulls random posts from my site

    You can check out the site http://www.dccollector.com and scroll to the bottom to see random posts.

    I would like, however to pull random posts from the 2nd page of the pagination.

    Here is the current query to pull the random posts…

    <?php $randompost = $wpdb->get_results(“SELECT ID FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_type = ‘post’ ORDER BY RAND() LIMIT 12”);

    What do I need to add to pull just from page 2 of the pagination? Or what do I need to take away or rewrite?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tedkord

    (@tedkord)

    but, where do I put that in the code? just stick a AND paged=2 in there?

    Here is the entire code for that. Just need to know where to stick paged=2

    <?php $randompost = $wpdb->get_results(“SELECT ID FROM $wpdb->posts WHERE post_status = ‘publish’ AND post_type = ‘post’ ORDER BY RAND() LIMIT 12”);

    foreach ($randompost as $post) {
    $ID = $post->ID;
    $postid = get_post($post->ID);
    $title = $postid->post_title;
    $values = $wpdb->get_var(“SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $ID AND meta_key = ‘Image’ “);
    ?>

    Thread Starter tedkord

    (@tedkord)

    Nevermind, figured it out. Thanks for the help gerbilk!

    If you have the opportunity, please describe your solution for subsequent readers. Thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘database query for random posts’ is closed to new replies.