WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] need to add a post limit and pagenation to this query (3 posts)

  1. munkeyhouse
    Member
    Posted 1 year ago #

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

    <?php
    
    $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. vtxyzzy
    Member
    Posted 1 year ago #

    I would consider using filters with a standard query_posts() to get the posts. That way, you have pagination built in.

    Here is an article describing some filters that might help.

  3. munkeyhouse
    Member
    Posted 1 year ago #

    thanks i will try it

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.