• Can someone help please?

    I am trying to allow my blog which is using custom posts to show random excerpts when a search is done. it doesn’t have to be ordered just random. As many of the posts start with the same sentences the excerpts all look the same so i would rather have it randomized.

    Any help with this is much appreciated thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • Use this to query for posts in random order:

    $query = new WP_Query( array( 'post_type' => 'use_your_custom_post_type', 'orderby' => 'rand', 'no_found_rows' => true ) );

    Your loop ( on the search page, I assume. ) could look something like this now:

    <?php $query = new WP_Query( array(
                                        'post_type' => 'use_your_custom_post_type',
                                        'orderby' => 'rand',
                                        'no_found_rows' => true ) ); ?>
    
    <?php while( $query->have_posts() ) : $query->the_post(); ?>
        <?php // do your loop stuff here ?>
    <?php endwhile; ?>

    I haven’t tested this, but it should do the trick. Let me know if you have a problem. ??

    Thread Starter desi4eva

    (@desi4eva)

    Sorry this is not to have the posts in random order but to show random selection of the excerpt instead. So say the posts are in order but the excerpt being shown is randomly selected from the posts content.

    Ouch. You’d need to parse the excerpt content in a custom function and then return a random portion. I’ll see if I can mock something up.

    Thread Starter desi4eva

    (@desi4eva)

    Thank you so much!

    [ Please do not bump, that’s not permitted here. ]

    Hi desi4eva,

    I completely forgot about this. Do you still need help on it or have you solved it?

    Thread Starter desi4eva

    (@desi4eva)

    Yes please sorry if you can.

    I’ll make something for you this evening ??

    Thread Starter desi4eva

    (@desi4eva)

    Ok thank you ??

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How can i display a random excerpt from custom posts?’ is closed to new replies.