Title: dlishus's Replies | WordPress.org

---

# dlishus

  [  ](https://wordpress.org/support/users/dlishus/)

 *   [Profile](https://wordpress.org/support/users/dlishus/)
 *   [Topics Started](https://wordpress.org/support/users/dlishus/topics/)
 *   [Replies Created](https://wordpress.org/support/users/dlishus/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/dlishus/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/dlishus/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/dlishus/engagements/)
 *   [Favorites](https://wordpress.org/support/users/dlishus/favorites/)

 Search replies:

## Forum Replies Created

Viewing 8 replies - 1 through 8 (of 8 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Events Manager - Calendar, Bookings, Tickets, and more!] datepicker problem](https://wordpress.org/support/topic/datepicker-problem/)
 *  [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [12 years, 7 months ago](https://wordpress.org/support/topic/datepicker-problem/#post-4245052)
 * Can you please tell me where you found the call? I’m having the same issue and
   having a hard time finding the culprit. Thank you!
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/page/2/#post-3191411)
 * I took another look and played around with the original code you supplied. I 
   removed the lines in bold and it’s working perfectly! My posts are sorted by 
   date of event and paginated.
 * <?php
    //Get today date $today = strtotime(“now”); $paged = (get_query_var(‘paged’))?
   get_query_var(‘paged’) : 1; $args = array ( ‘posts_per_page’ => ’20’, ‘post_type’
   => array(‘annnouncement’, ‘audio_ann’), ‘paged’ => $paged, ‘meta_query’=> array(**
   array(** ‘key’ => ‘date_of_event’, ‘value’ => date(“Y-m-d”, $today), ‘type’ =
   > ‘DATE’, ‘compare’ => ‘>’, ** )** ), ‘meta_key’ => ‘date_of_event’, ‘orderby’
   => ‘meta_value’, );
 * $the_query = new WP_Query($args);
    ?>
 * THANK YOU!
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/#post-3191409)
 * So close keesiemeijer! If I strip out the array for sorting by date, the posts
   appear with pagination. Thank you so much!
 * However, I still need to sort by date. When I placed the full code in, I got 
   this error:
    `PHP Parse error: syntax error, unexpected T_VARIABLE in /path/to/
   file on line 28`
 * Line 28 is:
    `$the_query = new WP_Query($args);`
 * Therefore, I think this is something small with the syntax. Can you help me with
   that? I really appreciate it!
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/#post-3191406)
 * esmi, I posted in the code you provided and am only getting the page title returned,
   not the title of the posts.
    I had to add an endif (which I needed anyways for
   pagenavi) or else I got a white screen
 *     ```
       <?php
           //Get today date
           $today = strtotime("now");
   
           //Revised query string
   
           $querystr = "
           	SELECT wposts.*
           	FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
           	WHERE wposts.ID = wpostmeta.post_id
           	AND wpostmeta.meta_key = 'date_of_event'
           	AND wpostmeta.meta_value > '" . date("m-d-Y", $today) . "'
           	AND wposts.post_status = 'publish'
           	AND wposts.post_type IN ('annnouncement', 'audio_ann')
           	ORDER BY wpostmeta.meta_value ASC
           	LIMIT 0, 20
           ";
   
       $dateIndexes = array(); ?>
       <ul>
       <?php while (have_posts()) : the_post(); ?>
       <article class="cat_article ">
       <?php the_title(); ?>
       </article> <!--End Cat Article-->
          <?php endwhile;?>
           <?php if(function_exists('wp_pagenavi')) :  wp_pagenavi();  endif; wp_reset_query();?>
       ```
   
 * Curly Bracket, I appreciate the code – but I wasn’t able to get it working either.
   I’ve added the code as you’ve supplied and did a var_dump on $myposts if you’d
   like to [take a look on what’s getting returned](http://www.ichurchnews.com/test-pag/).
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/#post-3191386)
 * My code looks like this:
 *     ```
       <?php
           //Get today date
           $today = strtotime("now");
   
           //Revised query string
   
           $querystr = "
           	SELECT wposts.*
           	FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
           	WHERE wposts.ID = wpostmeta.post_id
           	AND wpostmeta.meta_key = 'date_of_event'
           	AND wpostmeta.meta_value > '" . date("m-d-Y", $today) . "'
           	AND wposts.post_status = 'publish'
           	AND wposts.post_type IN ('annnouncement', 'audio_ann')
           	ORDER BY wpostmeta.meta_value ASC
           	LIMIT 0, 20
           ";
   
           $pageposts = $wpdb->get_results($querystr);
       var_dump($pageposts);
       $dateIndexes = array(); ?>
       <?php if ($pageposts->have_posts()) : ?>
       <ul>
       <?php while (have_posts()) : the_post(); ?>
       <article class="cat_article ">
       test
       </article> <!--End Cat Article-->
          <?php endwhile; endif; ?>
       ```
   
 * And I am getting values returned, [see here](http://www.ichurchnews.com/test-pag/)
 * I’m using a custom query because I need to query two custom post types, which
   are sorted by date of an event based on a custom field.
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/#post-3191384)
 * No luck, I’m getting the same issue “Call to a member function have_posts() on
   a non-object”
 * The white screen of death doesn’t show, but I tried this: Taking off the endif
   resulted in a white screen, and removing the “$pageposts = $wpdb->get_results(
   $querystr);?>” made it so there was an open that from $dateIndexes
 *     ```
       <?php
           //Get today date
           $today = strtotime("now");
   
           //Revised query string
   
           $querystr = "
           	SELECT wposts.*
           	FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
           	WHERE wposts.ID = wpostmeta.post_id
           	AND wpostmeta.meta_key = 'date_of_event'
           	AND wpostmeta.meta_value > '" . date("m-d-Y", $today) . "'
           	AND wposts.post_status = 'publish'
           	AND wposts.post_type IN ('annnouncement', 'audio_ann')
           	ORDER BY wpostmeta.meta_value ASC
           	LIMIT 0, 20
           ";
   
       $dateIndexes = array(); ?>
       <?php if ($pageposts->have_posts()) : ?>
       <ul>
       <?php while (have_posts()) : the_post(); ?>
       <article class="cat_article ">
       test
       </article> <!--End Cat Article-->
          <?php endwhile; endif; ?>
       ```
   
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/#post-3191355)
 * This is how I pasted it in:
 *     ```
       <?php
           //Get today date
           $today = strtotime("now");
   
           //Revised query string
   
           $querystr = "
           	SELECT wposts.*
           	FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
           	WHERE wposts.ID = wpostmeta.post_id
           	AND wpostmeta.meta_key = 'date_of_event'
           	AND wpostmeta.meta_value > '" . date("m-d-Y", $today) . "'
           	AND wposts.post_status = 'publish'
           	AND wposts.post_type IN ('annnouncement', 'audio_ann')
           	ORDER BY wpostmeta.meta_value ASC
           	LIMIT 0, 20
           ";
   
       $dateIndexes = array();
       $pageposts = $wpdb->get_results($querystr);?>
       <?php if ($pageposts->have_posts()) : ?>
       <ul>
       <?php while (have_posts()) : the_post(); ?>
       <article class="cat_article ">
       //html goes here
       </article> <!--End Cat Article-->
       <?php endwhile; ?>
       </ul>
       <?php else : ?>
       <p>No upcoming events</p>
       <?php endif; ?>
       ```
   
 * And I’m not getting any posts to display. My error log says
    PHP Fatal error:
   Call to a member function have_posts() on a non-object in /path/to/front-page.
   php
 * Thank you for your help thus far!
 *   Forum: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
   
   In reply to: [Add Pagination to querystr](https://wordpress.org/support/topic/add-pagination-to-querystr/)
 *  Thread Starter [dlishus](https://wordpress.org/support/users/dlishus/)
 * (@dlishus)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/add-pagination-to-querystr/#post-3191347)
 * I’m not a php expert, so I’m not sure how to change it. I tried switching out
   foreach with while, and then endforeach with endwhile and that didn’t work. Is
   this something you could help me with please?

Viewing 8 replies - 1 through 8 (of 8 total)