Restrict number of posts in a plugin
-
Hi I have this code in a plugin which I am converting into a widget.
It list all my posts in order of the event date. However it lists all my posts, what I want to do is just show 5 posts?Any idea on the below of where I would add ‘posts per page; or something?
Thanks very much in advance
function emw_events_list($atts, $content=NULL) { global $wpdb; $today = date('Y-m-d', strtotime('now')); $events = $wpdb->get_results("SELECT posts.id, posts.post_title, meta.meta_value FROM {$wpdb->prefix}postmeta as meta INNER JOIN {$wpdb->prefix}posts as posts ON (meta.post_id = posts.id) WHERE (meta.meta_key = 'event_date' AND meta.meta_value >= '{$today}' AND posts.post_status='publish' and posts.post_date < NOW()) ORDER BY meta.meta_value"); if(is_array($events)) { $output = "\t<ul class=\"events_list\">\n"; foreach ($events as $event) { $event_link = get_permalink($event->id); $event_date = date(get_option('date_format'), strtotime($event->meta_value)); $output .= "\t\t<li><a href=\"{$event_link}\">{$event->post_title}</a> ({$event_date})</li>\n"; } $output .= "\t</ul>\n"; } return $output; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Restrict number of posts in a plugin’ is closed to new replies.