Title: Paging while using a custom select query
Last modified: August 18, 2016

---

# Paging while using a custom select query

 *  Resolved [michuk](https://wordpress.org/support/users/michuk/)
 * (@michuk)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/)
 * I need to use a custom search query on my index.php page (I just display the 
   posts that have a special value in a special custom field). I used this approach:
   [http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query](http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query)
   to implement it.
 * I just have a problem with paging. It displays all the posts from the query. 
   How do I add default wordpress paging to the query (so that it shows only 5 –
   or whatever else is defined in WP – posts and “prev”, “next” buttons)?

Viewing 10 replies - 1 through 10 (of 10 total)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476452)
 * I could work with you to produce a proper SQL query for this, calling up the ‘
   paged’ and ‘posts_per_page’ values through the get_query_var() WordPress function
   to evaluate a proper LIMIT clause, and so on.
 * But you know what? I believe a plugin would be much cooler…
 * **Custom Home**
    [Download plugin](http://guff.szub.net/download/custom-home.php)
   | [View source](http://guff.szub.net/source/custom-home.php)
 * Before you activate the plugin on your blog, it has two user-configurable variables
   you should know about:
 * $key = The custom field key the plugin looks for. Default key name is ‘home’.
 * $value = The custom field value the plugin looks for. This is optional, and if
   left empty the plugin will match on the key only. Default value is ”.
 * You can change these variables either through the Plugin Editor in WordPress,
   or in a text editor offline.
 * Two points about the plugin: You’ll have to revert to [The Loop](http://codex.wordpress.org/The_Loop)
   in your index.php to use it. And yes, it plays nice with next/prev pagination.
 *  Thread Starter [michuk](https://wordpress.org/support/users/michuk/)
 * (@michuk)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476497)
 * Kafkaesqui – thanks a lot. I wanted to implement it as a plugin, too, but did
   not know how to dig into this… your code is a good start.
 * I need to customize the query (is it intensional that the WHERE clause relaces
   the original clause instead of appending it? — it displays unpublished posts,
   pages and everything by default), but this is still much easier than building
   own templates with custom queries for each one.
 * One more thing though: do you know how to specify that this plugin should be 
   used only on certain pages, in my case, a “/something/something_else/” page (
   which uses the a template something.php)?
 * Right now it just does a check for home but probably there is a way to check 
   for other pages (also the non-standard ones) too.
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476588)
 * “_is it intensional that the WHERE clause relaces the original clause instead
   of appending it?_“
 * That was *un*intentional. I’ve updated the plugin (R1.0.1) to provide a fix.
 * RE: One more thing
 * I’d look over the conditionals available in WordPress and see if any work for
   you:
 *  [http://codex.wordpress.org/Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)
 * If by ‘certain pages’ you mean [Pages](http://codex.wordpress.org/Pages), I’m
   not sure my work here will help as a Page can’t loop multiple posts through The
   Loop *unless* you’re overriding it with something like [query_posts()](http://codex.wordpress.org/Template_Tags/query_posts).
   They also don’t paginate posts (well, not without a lot of work!).
 * The parenthetical “non-standard ones” also leaves me wondering if the plugin 
   will work here, considering my assumptions in its creation are based on your 
   original mention of index.php.
 *  Thread Starter [michuk](https://wordpress.org/support/users/michuk/)
 * (@michuk)
 * [19 years, 6 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476662)
 * Thanks a lot. I used the approach from your plugin and build my own for my particular
   purpose. I achieved what I wanted so I’m marking the thread as resolved. Thanks
   again.
 *  [Xander](https://wordpress.org/support/users/xander/)
 * (@xander)
 * [19 years, 3 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476767)
 * Thanks Kafkaesqui; I was led here in my quest to find a simple way to display
   posts in a particular category by the post_modified date… your code provided 
   more help than I have found in all my other travels.
 *  [usuario](https://wordpress.org/support/users/usuario/)
 * (@usuario)
 * [19 years, 1 month ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476772)
 * Hey, thanks very much! I was really needing that!!
 * One prob! how to set to show only 5 posts per page??
 * I tried with: query_posts(‘posts_per_page=5’); before the loop, It shows only
   5 and create the arrow, but It gives me error when I tried to access the link
   to next/previous page… =(
 * HELP! 😀
 *  [usuario](https://wordpress.org/support/users/usuario/)
 * (@usuario)
 * [19 years ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476773)
 * Hello Kafkaesqui,
 * Could you please help me a little bit? I really liked your plugin and it helped
   me a lot, I just want to know… if you can help me, use it in another pages besides“
   home”. I have a category templates, and I wanted to use it in this template too,
   could you help me?
 * thanks.
 *  [usuario](https://wordpress.org/support/users/usuario/)
 * (@usuario)
 * [19 years ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476775)
 * Hey Kafkaesqui,
 * Could you help in the question above??
 * I need to can use this plugin with more than one key/value…. Like, in the “home
   page” use the key/value = test/test and in the page “top news” use like test2/
   test2.
 * Thank you very much.
 *  [usuario](https://wordpress.org/support/users/usuario/)
 * (@usuario)
 * [19 years ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476776)
 * Hello everybody, I’m really needing to be possible use this plugin in other than
   the page… I mean, more than 2 places, with keys/values different. I tried to 
   make a “if is_page()” inside the plugin code to give different values to the 
   variable of the key/values, but it didn’t work =/
 * Really appreciate your help.
 *  [joel01](https://wordpress.org/support/users/joel01/)
 * (@joel01)
 * [18 years, 7 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476791)
 * Kafkaesqui, you’ve made my day! Thank you for your code, I adapted it to suit
   my needs.
 * [@usuario](https://wordpress.org/support/users/usuario/):
    Make sure you insert
   any additional ‘if’ statements before the ‘posts_where’ function returns. You
   should be able to use as many as you like for any number of situations. Just 
   make sure you follow the format of the examples listed on the Conditional Tags
   page that Kafkaesqui linked to.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘Paging while using a custom select query’ is closed to new replies.

## Tags

 * [custom-query](https://wordpress.org/support/topic-tag/custom-query/)
 * [paging](https://wordpress.org/support/topic-tag/paging/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 5 participants
 * Last reply from: [joel01](https://wordpress.org/support/users/joel01/)
 * Last activity: [18 years, 7 months ago](https://wordpress.org/support/topic/paging-while-using-a-custom-select-query/#post-476791)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
