I have a search results page that I want to limit results on i.e. posts_per_page
. However if I use query_posts('posts_per_page=6')
I lose the original query.
How do I alter my query without damaging the original?
I have a search results page that I want to limit results on i.e. posts_per_page
. However if I use query_posts('posts_per_page=6')
I lose the original query.
How do I alter my query without damaging the original?
Comments are closed.
You can use the
pre_get_posts
filter to access/alter the$query
object. In functions.php:Never ever use
query_posts
, it breaks the main query object ($wp_query
) and all functionality that relies on the main query object. It also breaks page functionality. Apart from that, it is slow and reruns queries.query_posts
should be on top of your most evil list together with functions likecreate_function()
,eval()
andextract()
.If you need to alter the main query, always use
pre_get_posts
to do so. Never change the main query with a custom one, it might solve one problem, but it creates many other.The following will work