WordPress.org

Forums

[resolved] Adding a random post (3 posts)

  1. eronkid
    Member
    Posted 5 years ago #

    Hi there,

    I am not a coder and I don't have any above level skills in php. But I found this piece of code for placing a specific category and it WORKS!

    <?php
    $featuredPosts = new WP_Query();
    $featuredPosts->query('category_name=featured&showposts=1');

    while($featuredPosts->have_posts()) :
    $featuredPosts->the_post();?>

    <h3>"><?php the_title(); ?></h3>
    <p><img src="<?php echo get_post_meta($post->ID, 'featurethumb', true); ?>"/><?php the_excerpt(); ?></p>
    <p class="readit">">Read more»</p>

    <?php endwhile; ?>

    Now my problem is, how can I make a random post from that specific category? I guess a small insertion of code, something like that. Thank you very much for taking some time regarding my problem.

  2. MichaelH
    Member
    Posted 5 years ago #

    This should work:

    $featuredPosts->query('category_name=featured&showposts=1&orderby=rand');
  3. eronkid
    Member
    Posted 5 years ago #

    Thank you MichaelH!
    Yes, it really works fine.

Topic Closed

This topic has been closed to new replies.

About this Topic