Thanks for your question, for the shortcode text and for supplying the additional details in response to Greg’s question.
I entered your shortcode text on my test system and had a look at the database activity they generate. I believe the performance issues you are experiencing are related to the database queries required to get the results you want.
WordPress taxonomies are a powerful tool but they can require complex queries to get the desired results. MLA uses the WordPress WP_Query
class to query the database. That’s usually the best way to get results, but in cases like yours it can have performance problems.
You wrote “it seems like querying all the records in the same category … That is true and it is part of the problem. Your shortcode includes orderby=’menu_order DESC,ID DESC’
, which means that all of the items in the entire category must be retrieved and sorted before the posts_per_page=20
can be applied. There is no way of knowing which 20 items are right without sorting them all.
Another potential problem is that all of the rows in the posts table must be joined to the term_relationships table to find which items have been assigned to the category you want. The performance on this step is affected by the total number of posts/pages/attachments and the total number of term assignments.
Since the Media Library items share the posts table with posts and pages, additional query logic is required to filter out just the attachments, and additional tests are made for post_status and post_mime_type.
If your application has certain restrictions you can improve performance a lot by using custom SQL queries instead of relying on WP_Query
. For example, if you know that the terms you are filtering on are only assigned to images you can eliminate the tests for post_type, post_status and post_mime_type. There are several earlier support topics along lines similar to yours:
How to use custom taxonomy in my_custom_sql
REALLY Slow Queries…….. Help! ??
Slow queries
There is an MLA example plugin, “MLA tax query Example”, that was developed to resolve these topics. You may find it works in your application. If you would like to try installing the example plugin and working with it, let me know and I will give you more specific help with that.
I hope the above explanations and earlier topics shed some light on your performance issues. I will leave this topic unresolved until I hear back from you. Thanks for your interest in the plugin.