WordPress.org

Ready to get started?Download WordPress

Forums

get content from category 5 with wpdb (2 posts)

  1. mserafim
    Member
    Posted 6 years ago #

    i have this code:

    $rand_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY RAND() LIMIT 1");
          query_posts("p=$rand_id");
    	while (have_posts()) : the_post();
    	the_title();
    
    endwhile;

    The code retrive random article titles from the entire blog.
    What i want is to retrive content from only one category, for ex category ID 5.

    Thank you.

  2. MichaelH
    Member
    Posted 6 years ago #

    Well if this plugin/widget doesn't work for you, at least you can look at the code for how they do it.
    http://wordpress.org/extend/plugins/random-one-cat-widget

Topic Closed

This topic has been closed to new replies.

About this Topic