menu

arrow_back How to optimize WP_Query?

by
1 vote
Good afternoon. I am currently doing a project on WP and in the process found out that there will be more than 5 WP_Query loops on the page. Is there any way to optimize them? How have you handled these situations?

3 Comments

If you want an answer, be specific about the question. I need more than 5 cycles on one page so...

The 1st loop will output this...

The 2nd is.

...

Cycle 7 will output this...

Then maybe we can figure out that you can get by with three.
Dmitry , okay.
The 1st cycle outputs posts with a video category
The 2nd cycle outputs posts with a news category
The 3rd loop searches for the desired custom sp_league entry by ID
The 4th loop outputs the custom sp_event posts linked to the custom sp_team entry
The 5th loop outputs the custom sp_event posts linked to the custom sp_team entry
The 6th loop outputs popular posts with a custom sp_league type
Cycle 7 outputs 2 categories of video and news mixed together

The 4th and 5th cycles did separately because they should give out 10 results each for a narrow search.
The 3rd loop could be replaced by get_post($ID), but that's not the case.

1 Answer

by
 
Best answer
0 votes
You can use wpdb, form one giant query in the database and pull all the necessary data at once, bypassing all the hooks of the GP.