• Hi,

    I managed to display a random post by creating a new page template and using the query_posts function. But it seems I can’t display any other content on that page if I use query_posts.

    I’ve read that I should use the get_posts function, This is the code I have at the moment:

    <?php
    			$args = array( 'numberposts' => 1, 'orderby' => 'rand' );
    			$rand_posts = get_posts( $args );
    			foreach( $rand_posts as $post ) : ?>
    
    		<?php endforeach; ?>

    The problem is I don’t know what do write after foreach( $rand_posts as $post ) : ?> in order to display the post text and not the permalink leading to the post.

    Can anybody help?

Viewing 1 replies (of 1 total)
  • Thread Starter tudorc11

    (@tudorc11)

    Nobody can give me a tip on what function to use to display the post? At least tell me if this is achievable or not. Thank you!

Viewing 1 replies (of 1 total)
  • The topic ‘Using get_posts to to display a random post on a page’ is closed to new replies.