how to page custom database query (to sort by custom field)?
-
I have a Page template with the following query to list all posts ordered by the “Author” custom field (i.e., author of the document posted, not the author of the post).
<?php $pageposts = $wpdb->get_results("SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'Author' AND wposts.post_status = 'publish' ORDER BY wpostmeta.meta_value ASC", OBJECT); if ($pageposts): foreach ($pageposts as $post): setup_postdata($post); ?> ... etc.
How can I paginate this instead of listing all 360+ posts at once?
- The topic ‘how to page custom database query (to sort by custom field)?’ is closed to new replies.