WordPress.org

Ready to get started?Download WordPress

Forums

query_posts problem (3 posts)

  1. dmpp
    Member
    Posted 2 years ago #

    So here is my code...

    query_posts(array('posts_per_page'=>-1,
    				'post_type'=>'event',
    				'orderby'=>'meta_value',
    				'meta_key'=>'event_date',
    				'order'=>'ASC'
    			));

    That outputs all posts... works just fine.

    What I want to do is limit it to 5...
    so I changed it to:

    query_posts(array('posts_per_page'=>'5',
    				'post_type'=>'event',
    				'orderby'=>'meta_value',
    				'meta_key'=>'event_date',
    				'order'=>'ASC'
    			));

    that didn't do it.

    thoughts?

  2. raskull
    Member
    Posted 2 years ago #

    Try taking the single quotes off of '5' so it reads 5

  3. dmpp
    Member
    Posted 2 years ago #

    I've tried that... what happens with that, is that I get up to 5 results for the current month... so my events cat has 2 for August in it, and so it only shows 2... but there are 6 in September...

    here is all the code for it...

    $event_cats=get_post_meta($post->ID,'event_categories',false);
    
    			query_posts(array('posts_per_page'=>5,
    				'post_type'=>'event',
    				'orderby'=>'meta_value',
    				'meta_key'=>'event_date',
    				'order'=>'ASC'
    			));
    			while ( have_posts() ){
    				the_post();
    				if(in_category($event_cats) || !$event_cats){
    					$end_date=get_post_meta($post->ID, 'event_date_end', true);
    					$start_date=get_post_meta($post->ID, 'event_date', true);
    
    					if(strtotime($start_date)>=(time()-(2*24*60*60))){
    						echo "<p>";
    						echo date("M.", strtotime($start_date)) ."<br />";
    						echo date("d", strtotime($start_date)) ."<br />";
    						echo "<a href='".get_permalink($post->ID)."'>".get_the_title() ."</a>";
    						echo get_post_meta($post->ID, 'event_sub_title', true);
    						echo "</p>";
    					}
    				}
    
    			}

Topic Closed

This topic has been closed to new replies.

About this Topic