Support » Plugins » Hacks » Add Pagination to querystr

  • dlishus

    (@dlishus)


    I have a query combining two post types, and sorting by a custom field which goes by date. I’m lost on how to add page navigation. I’ve installed wp-page-navi and can’t seem to get it to work within my code.

    <?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): ?>
    <ul>
    <?php foreach ($pageposts as $post): ?>
    <?php setup_postdata($post);?>
    
       <article class="cat_article ">
           //html for posts goes here
        </article> <!--End Cat Article-->
    
        <?php endforeach; ?>
        </ul>
        <?php else : ?>
        <p>No upcoming events</p>
        <?php endif; ?>
Viewing 3 replies - 16 through 18 (of 18 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    That’s strange, I don’t get any errors. Can you paste the full code of the template file here.

    dlishus

    (@dlishus)

    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!

    Moderator keesiemeijer

    (@keesiemeijer)

    moderator

    You’re welcome. I’m glad you got it resolved.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Add Pagination to querystr’ is closed to new replies.