WordPress.org

Support

Support » How-To and Troubleshooting » query_posts problem

query_posts problem

  • 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try taking the single quotes off of ‘5’ so it reads 5

    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>";
    					}
    				}
    
    			}
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘query_posts problem’ is closed to new replies.