Tag Info

Hot answers tagged

3

There are approx. 10,000 items returned by the query. That's your problem right there. No matter what you do inside the loop, WordPress is still loading 10,000 post objects into memory. Batch it up and sprinkle a little magic in your query arguments: $args = array( 'fields' => 'ids', // MAGIC! Just get an array of id's, no objects ...


3

The standard query for posts uses orderby => 'post_date' and order => 'DESC'. The best candidate for arbitrary sort of posts would be orderby => 'menu_order' and order => 'ASC'. The menu_order is not generally used for posts but it is safe to be used. As suggested by Pieter Goosen use action hook pre_get_posts: add_action( 'pre_get_posts', ...


1

Firstly, you are invoking an infinite loop, which causes the memory exhaustion. To avoid it, put the following at the beginning of your function: // avoid infinite loop remove_action( 'pre_get_posts', __FUNCTION__ ); It makes sure the you are not hooking it into pre_get_posts over and over again, re-initiating your get_posts() call over and over again. ...



Only top voted, non community-wiki answers of a minimum length are eligible