• Hi!

    I’ve trying to do this for the past week or so and I seem to have exhausted my patience. What I want to do sounds simple, but I can’t find any documentation for it.

    I have an events website. Once an event happens a recap of the event is written in a custom field. The thing is that the recap may not be written right away.

    So what I want to do is have a way to display the most recent post that has a recap.

    For Example:

    Post A: dated 1 day ago, has no recap
    Post B: dated 5 days ago, has recap
    Loop displays Post B, the latest post with a recap in a custom field.

    This is what I have, which does not work:

    <?php query_posts('cat=5&showposts=1'); ?>
    <?php while (have_posts()) : the_post(); ?>
    
    <?php $check = get_posts('numberposts=1'); ?>
    <?php $eventrecap = get_post_meta($post->ID, 'event recap', true);
    	if ($eventrecap=="") continue; ?>

    I’m pretty new to conditional statements and any help is appreciated!

Viewing 1 replies (of 1 total)
  • I didn’t test but try:

    <?php
    $args=array(
      'cat' => 5,
      'meta_key'=>'recap',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => 1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

Viewing 1 replies (of 1 total)
  • The topic ‘How to skip posts based on Custom Field’ is closed to new replies.