Quantcast
Channel: WordPress.org Forums » All Posts
Viewing all articles
Browse latest Browse all 113066

Aboobacker P on "Problem with sorting posts with meta field date"

$
0
0

Hi,
I am so tired with trying this and I am still stuck with the problem.
I have a post type named uspa_events with a custom meta field ab_event_date to set the event date.

What I want is I want to display only the upcoming events in a sorted order. I can display the upcoming events based on comparing the event date meta with today's date.

But they are not in a sorted order! please refer the scrolling show under under Events in http://growpolo.com.

Code:

<?php
	if( get_option(PREFIX.'no_of_events') != 0 ) {
		$EvntCount = get_option(PREFIX.'no_of_events');
	}
	else { $EvntCount = 5; }
	$i = 1;
	query_posts('post_type=uspa_events&orderby=meta_value_num&meta_key=ab_event_date&order=DESC&showposts=1000');
	while(have_posts()):the_post();
		$today = strtotime(date("Y-m-d"));
		$event_date = strtotime(get_post_meta($post->ID, 'ab_event_date', true)); 

		if ($event_date >= $today) { ?>
			<?php if( $i <= $EvntCount ) { ?>
				<li>
					<?php if( has_post_thumbnail() ) { the_post_thumbnail('event_img'); }
					else { ?>
						<img src="<?php echo IMG; ?>/img14.jpg" width="964" height="316" alt="image" />
					<?php } ?>
					<div class="description">
						<em class="line"> </em>
						<div class="holder">
							<em class="date"><?php echo date("M d",$event_date); ?></em>
							<strong class="title"><?php the_title();?></strong>
							<div class="row"><?php the_content(); ?></div>
						</div>
					 </div>
				</li>
	   <?php $i++; } } ?>
<?php endwhile; wp_reset_query(); ?>

Please help.

Advance Thanks


Viewing all articles
Browse latest Browse all 113066

Latest Images

Trending Articles



Latest Images