WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use the below code to display the first 5 results.

<ul class="category_list_view" id="widget_index_upcomming_events_id">
global $post,$wpdb;
$post_number = 5;
$category1 = $category;
$today = date('Y-m-d G:i:s');
if($category) {
 $category = "'".str_replace(",","','",$category)."'";
 $where .= "and p.ID in (select tr.object_id from $wpdb->term_relationships tr join $wpdb->term_taxonomy t on t.term_taxonomy_id=tr.term_taxonomy_id where t.term_id in ($category))";
$today = date('Y-m-d G:i:s');
@$where .= " AND (p.ID in (select $wpdb->postmeta.post_id from $wpdb->postmeta where $wpdb->postmeta.meta_key='st_date' and date_format($wpdb->postmeta.meta_value,'%Y-%m-%d %G:%i:%s') >'".$today."')) ";

$sql = "select p.* from $wpdb->posts p where p.post_type='".CUSTOM_POST_TYPE1."' and p.post_status='publish' $where order by $orderby limit $post_number";

$latest_menus = $wpdb->get_results($sql);
 if($latest_menus) {

    foreach($latest_menus as $post) :
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
        <?php echo get_post_meta($post->ID,'address',true); ?>

 } else {
  echo "<p>".UPCOMING_NOT_FOUND_TEXT."</p>";

I wanted to display the next 5 results from the last displayed result of the code above using ajax.

Adding <a>Load More</a> at the end if there is more than 5 results and add No more results if there is only 5 results. Also, when I click the <a>Load More</a> and there are no more results to display, then replace <a>Load More</a> with <b>No more results</b>

I don't know how to do ajax with the code above since im not familiar with jquery.

Please help..

share|improve this question
There are many posts that would show the use of AJAX to get the result you want! – sri Jun 17 '14 at 13:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.