Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

AndySpeed on "Display random recent post custom field"

$
0
0

Hi,

I am looking to display, in a random order, a custom field from any one of the five most recent posts which:

1) have something in the custom field
2) fall within the specified category

What I have come up with is the following:

<?php query_posts('showposts=5&cat=129,131,318&offset=0&order=rand'); ?><?php if (have_posts()) : while (have_posts()) : the_post(); ?><?php $mykey_values = get_post_custom_values('Quote'); foreach ( $mykey_values as $key => $value ) { echo "$value"; } ?><?php endwhile; ?><?php endif; ?>

However this isn't working. The random code isn't working. Can anyone advise as to what I may be doing wrong and what can be amended to produce the desired result?

Essentially the custom field 'Quote' contains a line of text from an article. I'd like to have this code randomly select a 'Quote' custom field from any one of the five most recent articles which have this field populated. It's key that only one quote gets displayed at a time - not all five.

Thanks,

Andy


Viewing all articles
Browse latest Browse all 8245

Trending Articles