Quantcast
Channel: When to use WP_query(), query_posts() and pre_get_posts - WordPress Development Stack Exchange
Browsing latest articles
Browse All 6 View Live

Answer by prosti for When to use WP_query(), query_posts() and pre_get_posts

Just to outline some improvements to the accepted answer since WordPress evolved over the time and some things are different now (five years later): pre_get_posts is a filter, for altering any query....

View Article



Answer by T.Todua for When to use WP_query(), query_posts() and pre_get_posts

I modify WordPress query from functions.php: //unfortunately, "IS_PAGE" condition doesn't work in pre_get_posts (it's WORDPRESS behaviour) //so you can use `add_filter('posts_where', ....);` OR modify...

View Article

Answer by Lukas Pecinka for When to use WP_query(), query_posts() and...

There are legitimate scenarios for using query_posts($query), for example: You want to display a list of posts or custom-post-type posts on a page (using a page template) You want to make pagination of...

View Article

Answer by Rarst for When to use WP_query(), query_posts() and pre_get_posts

There are two different contexts for loops: main loop that happens based on URL request and is processed before templates are loaded secondary loops that happen in any other way, called from template...

View Article

Answer by Stephen Harris for When to use WP_query(), query_posts() and...

You are right to say: Never use query_posts anymore pre_get_posts pre_get_posts is a filter, for altering any query. It is most often used to alter only the 'main query':...

View Article


When to use WP_query(), query_posts() and pre_get_posts

I read @nacin's You don't know Query yesterday and was sent down a bit of a querying rabbit hole. Before yesterday, I was (wrongly) using query_posts() for all my querying needs. Now I'm a little bit...

View Article
Browsing latest articles
Browse All 6 View Live




Latest Images