admin管理员组文章数量:1426959
I'm working now on high performance Wordpress website and it requires me to analyze a lot of queries, caching options etc. I've discovered that if you use get_the_post_thumbnail()
even within the loop, then WordPress makes a query for every post's thumbnail url.
So if you've got your page set to display 25 posts with thumbnails, it makes 25 additional queries to retrieve image URL.
Without using get_the_post_thumbnail()
I'm reducing query number from 49 to 4. A big number. However, thumbnails are really needed for this theme.
Do you know if there's any way to include post thumbnail URL in the post object by default?
I'm working now on high performance Wordpress website and it requires me to analyze a lot of queries, caching options etc. I've discovered that if you use get_the_post_thumbnail()
even within the loop, then WordPress makes a query for every post's thumbnail url.
So if you've got your page set to display 25 posts with thumbnails, it makes 25 additional queries to retrieve image URL.
Without using get_the_post_thumbnail()
I'm reducing query number from 49 to 4. A big number. However, thumbnails are really needed for this theme.
Do you know if there's any way to include post thumbnail URL in the post object by default?
Share Improve this question edited May 16, 2019 at 8:15 bueltge 17.1k7 gold badges62 silver badges97 bronze badges asked May 15, 2019 at 21:13 TheDraomTheDraom 111 bronze badge1 Answer
Reset to default 0I believe you can fetch that data using setup_postdata() which lets you access all the data relating to a post and use it with standard template tags (in your case, the_post_thumbnail).
There is a great tutorial here: https://wpshout/setup_postdata-template-tags-need-custom-wp_post-arrays-crave/
Important to note that you first have to setup the global $post and you have to be sure to reset using wp_reset_postdata at the end of your query.
I hope this works for you!
本文标签: Including post thumbnail url in loop39s post object to reduce number of queries
版权声明:本文标题:Including post thumbnail url in loop's post object to reduce number of queries 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745475848a2659958.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论