mysql query paging

Hi
I have made an sql query that gets several posts according the parameters that i’ve selected.
I’m showing these posts but the inner paging within
wordpress doesnt do anything.
It shows me that there are more pages but when i select the page number it shows me the same results as before.
That makes sense because it probably runs the sql query again.
I’m using WordPress and BuddyPress.
How can i page between these query results?

UPDATE:
here is the code im using

$sql = "SELECT post_title, post_date, post_excerpt, guid, ID FROM wp_posts,wp_term_taxonomy, wp_terms, wp_term_relationships WHERE (post_status="publish" or post_status="inherit") and wp_term_taxonomy.term_taxonomy_id = ".$cat." and wp_posts.ID = wp_term_relationships.object_id and wp_terms.term_id = wp_term_taxonomy.term_taxonomy_id and wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id and wp_term_taxonomy.taxonomy = 'category' ORDER by post_date DESC";
$matching_posts = $wpdb->get_results($sql,OBJECT);
<?php if ( have_posts() ) : ?>

  <?php foreach ($matching_posts as $post): ?>
  <?php setup_postdata($post);

then im showing the info i want like title.

1 Answer
1

You need to use get_posts(), have_posts(), and the_post() for the API functions to work.

Leave a Comment