Ready to get started?Download WordPress


[resolved] adding a post limit and pagination to a custom meta query (5 posts)

  1. munkeyhouse
    Posted 1 year ago #

    need to add a post limit of 15 per page and pagination to this query... thx in advance

    $querystr = "
    	SELECT wposts.*, ABS(
    REPLACE(SUBSTRING(wpostmeta.meta_value, 2)
    , ',', '')) AS sortby
    	FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    	WHERE wposts.ID = wpostmeta.post_id
    	AND wpostmeta.meta_key = 'price'
            AND wpostmeta.meta_value != '$TBA'
            AND wpostmeta.meta_value != 'REQUEST $'
            AND ABS(REPLACE(REPLACE(wpostmeta.meta_value, '$', ''), ',', '')) > '150'
            AND ABS(REPLACE(REPLACE(wpostmeta.meta_value, '$', ''), ',', '')) < '500'
    		AND post_status='publish'
            ORDER BY sortby asc
    $pageposts = $wpdb->get_results($querystr, OBJECT); 
    if ($pageposts) : foreach ($pageposts as $post): setup_postdata($post);
    	$my_meta = get_post_meta(get_the_ID(), '_my_meta', TRUE);
        <?php get_template_part( 'grid', get_post_format() ); ?>
        <?php endforeach; endif; ?>
  2. bcworkz
    Posted 1 year ago #

    $wpdb or mySQL know nothing of pagination, your code would have to manage it on it's own. You should try to get your query into WP_Query in conjunction with the 'posts_clauses' filter so that the resulting query object can manage the pagination.

  3. bcworkz
    Posted 1 year ago #

    ---ignore my 2nd post, had a weird server error that wasn't---

  4. munkeyhouse
    Posted 1 year ago #

    thanks i will try that... makes sense :)

  5. munkeyhouse
    Posted 1 year ago #


Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.