WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using this to get the posts:

(...) if ( empty( $categories_defined) ) {

  $posts = get_posts($args);
} else {
  global $wpdb;
  $posts = $wpdb->get_results( $wpdb->prepare(
    "SELECT * FROM $wpdb->posts WHERE
    post_type = 'post' AND post_status = 'publish' AND
    post_title LIKE %s  ORDER BY post_title ASC LIMIT 50",
    $categories_defined . '%'
  ) );

So I have already limited my posts, which is working fine, but I can't get the pagination. I tried using a plugin, shortcodes and the native pagination, but I can't find the problem. Can someone help me out with this? I'd like to have a next and previous pagination together with the navigation with numbers... One for above, one beneath the posts...

share|improve this question
Where you put this code? In a page or in a singular post or in an archive template? Tip: for the else you can use the s argument for get_posts instad writng a custom SQL – gmazzap Aug 4 '13 at 9:30
In a page that I am using. Can you provide an example of what you mean with s? – user1627363 Aug 4 '13 at 9:45
Please take a look at like_prepare() for your query. – kaiser Aug 4 '13 at 11:08
Don't get it. What does it? There is not much documentation out there? – user1627363 Aug 4 '13 at 11:19
Why are you not just using get_posts() for this? – Pippin Aug 4 '13 at 17:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.