WP_Query and custom_field sorting question (3 posts)

  1. Creatier
    Posted 5 years ago #

    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(); ?>
    <?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. :)

  2. MichaelH
    Posted 5 years ago #

      '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()

  3. Creatier
    Posted 5 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic