Quantcast
Viewing all articles
Browse latest Browse all 8245

charlesdunworth on "query and order posts by custom time field"

I am trying to display a list of custom types ordered by a custom field type of date, and to show only those posts after today's date.

I have this code (which I feel should work) which is in functions.php and called in a template file

global $post;
$today = time("DD dd/mm h:mm tt");
$posts = get_posts(array(
	'post_type' => 'custom_type',
	'show_posts'	=> 3,
	'meta_key'		=> 'custom_date',
	'meta_value' => $today,
	'meta_compare' => '>=',
	'orderby'		=> 'custom_date',
	'order'			=> 'ASC'
	)
);

foreach($posts as $post) : setup_postdata($post); ?>
	 <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></p>
	 <p class="kickoff"><?php the_field('custom_date'); ?></p>
<?php endforeach;

It only returns one post. Can anyone tell me why?


Viewing all articles
Browse latest Browse all 8245

Trending Articles