There's something I try to understand about the process of querying posts in wordpress:
Lets say I have this code:
$args = array{
'cat' => 'animals',
'posts_per_page' => 3
}
$the_query = new WP_Query($args);
So theoretically wordpress go to the database, going through all posts, and for each post, from the first to the last, it "asks" the post for it's category, if the answer is "animals" it grabs that post and move to the one after, if the category is something else, it skip that post and move to the one after. And repeat that process n times?
Or, since I set posts_per_page
to 3, after the third post that matchs "animals", the process it stops?
If the answer is the first, How can I optimize the code if, let's say I have 300 posts under "animals", but I need only the latest 3. How can I tell wordpress to stop checking after the third one that match "animals"?
I'm asking this since I'm working on a custom theme for site with more then 40000 posts, the homepage need to have at least 5 different queries like the one above, and I want to make it as efficient as possible.
I hope that's make sense.
Thanks in advance!