Posted By

davebowker on 12/16/08


php wordpress query field custom queryposts

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


Custom Wordpress query using custom fields outside the loop

 / Published in: PHP

$quote -- name of function post_type=page -- remove to query posts orderby=rand -- random order showposts=1 -- limit to 1 post

effect -- displays 1 random custom excerpt outside of the loop

  1. <?php $quote = get_posts('post_type=page&showposts=1&meta_key=quote&orderby=rand'); foreach($quote as $post) : setup_postdata($post); ?>
  2. <li class="quote"><a href="<?php the_permalink(); ?>" title="Read the <?php the_title(); ?> case study"><?php echo get_post_meta($post->ID, "quote", true); ?></a>
  3. <em><?php echo get_post_meta($post->ID, "quote-author", true); ?></em></li>
  4. <?php endforeach; ?>

Report this snippet  

You need to login to post a comment.