Random post for sidebar in certain category (1 post)

  1. westondeboer
    Posted 8 years ago #

    After the 2.3 upgrade i am having problems with the code that i have for random posts to be displayed in the sidebar.

    global $wpdb;
    $random_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts , $wpdb->terms WHERE $wpdb->terms.magazine = '1' AND term_id = '2' AND post_status = 'publish' ORDER BY RAND() LIMIT 1");
    if($random_posts) : foreach($random_posts as $post) : setup_postdata($post);

    the code is now showing non published articles and 'pages'.

    I have added another column to the terms table so i can easily do this random article from the archives.

    Can anyone help?

Topic Closed

This topic has been closed to new replies.

About this Topic

  • RSS feed for this topic
  • Started 8 years ago by westondeboer
  • This topic is not a support question
  • WordPress version: 2.3