• Creatier

    (@creatier)


    I wonder if anyone might be able to help me out:)
    I have a custom post type called events and I would like to display the 3 latest events with the custom field “featured” set to “Ja” (Dutch equivalent of Yes).

    So far I’ve got my widget set up like this:

    <?php $loop = new WP_Query( array( 'post_type' => 'Event')); ?>
    <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
    
    <?php the_title( '<h4 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h4>' ); ?>
    	<div class="entry-content">
    		<?php the_content(); ?>
    	</div>
    <?php endwhile; ?>

    This does the trick, but does not filter by the featured custom value. I’ve been looking in the function reference for a clear example, but could not find one. Any help would be greatly appreciated. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    (@michaelh)

    $args=array(
      'meta_key' => 'featured',
      'meta_value' => 'JA',
      'post_type' => 'event',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);

    See query_posts()

    Thread Starter Creatier

    (@creatier)

    Great`! Thanks for pointing me in the right direction. Got it to work!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query and custom_field sorting question’ is closed to new replies.