Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

Best approach to create Hot and Trending sections

In my personal opinion, this can get a bit resource intensive, so you will need to implement some type of cache system, or even look at transient

What you want to do is to extent your current post view function or even create one on the side for this. You would want to capture each view twice, once for normal page view as you are currently doing ($count_key) , and secondly for a custom view function using maybe $custom_count_key

Now, this is how $custom_count_key would work:

  • A page view is recorded when the page (post) is visited as per normal

  • This field is cleaned out (all data deleted) daily/weekly/etc depending on how you would like to define your Trending section. This again would set the value to 0 at the start of a new day/week/etc

What you will need to do:

  • As stated, either extend or write another page view function to store daily/weekly/etc views

  • Create a function that will run at a specific time daily/weekly/etc (whichever suite your needs better) which will delete/clean-out the values of that meta field.

  • Create your custom query to query an x amount of posts which has the highest amount of views for the specific day/week/etc. The posts been retrieved by this query will differ through out the day/week/etc as each post’s views are increased due to page visits.

  • You can also save the results from a day/week/etc in the db for future reference before deleteting/cleaning out the current values at the end of that specific day/week/etc, but that is up to you and might even be just a waste of time and space

This is just a basic idea that you can use. I’m not in the position to code something like this now, but is would be really nice if you use this idea to post your final working solution to this

Good luck and all the best on this project

Related Posts:

  1. How to only display posts whose meta_value field is not empty?
  2. Can wp_query return posts meta in a single request?
  3. order by numeric value for meta value
  4. How do I query for posts by partial meta key?
  5. Use REGEXP in WP_Query meta_query key
  6. WordPress retrieving meta data for all custom post types in list view
  7. Order by optional meta key?
  8. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  9. Reduce or prevent calling of update_meta_cache
  10. Is there a way to extend WP_query so Custom Post Types can have properties?
  11. What is the most efficient way of querying posts based on visits and date for current day?
  12. Getting attachments by meta value
  13. WP_Query displaying ALL posts
  14. meta_query where value is equal to given value
  15. Query Custom Meta Value with Increment
  16. WP-CLI How to generate a list of posts with corresponding meta values
  17. What is an efficient way to query based on post_meta?
  18. WP_Query not working as expected for attachments and custom meta_query
  19. How to count post meta key values for all posts in database
  20. Group posts by meta_key
  21. How should I use posts_where to change meta_value from a string to integer?
  22. How can I create a WP_Query that returns posts where one meta_value
  23. WordPress altering my custom query, How to fix it?
  24. WP Meta Query for some meta (array) values
  25. WP Query post meta value
  26. Would this post meta be better added to the post table rather than post_meta table
  27. Custom URl parameter
  28. query posts in functions.php and update a field
  29. Compile meta values from custom loop into array and then calculate sum total
  30. How to get sum of meta_values of a meta_key in wp_query according to conditions
  31. how to fire join query with post_meta
  32. WP_Query, custom sort and custom filter
  33. Order posts by meta value and Date
  34. Efficient way to update multiple post meta
  35. Show most popular post of last 12 months
  36. How to make orderby ‘meta_value_num’ OPTIONAL?
  37. Query Posts depends on custom field inside repeater field using acf
  38. Query post with meta_query where date is not in future
  39. Minimising Database Queries when using Advanced Custom Fields
  40. Get meta info related to current post
  41. Select from wp_post and multiple meta_value from wp_postmeta
  42. Pull post meta with post_query?
  43. Most popular post for last 7 days
  44. Group WP_Query by meta_key date
  45. WP_query posts closest to todays date
  46. exclude posts with a specific custom field and value
  47. Inserting serialized value into wp_postmeta using update_post_meta
  48. How to make Meta Query case sensitive?
  49. Performance when getting post meta for post retrieved by meta value
  50. Get attachment by meta_key value
  51. Display custom field meta outside loop, site wide
  52. Using hook to use DISTINCT in a wp_query
  53. Fetch Record based on meta key dates
  54. Where to put meta Keys
  55. how to make members list directory through wordpress post custom meta key.
  56. How do I query for posts by partial meta key?
  57. Large AND OR query timing out
  58. Display most popular in the past two days
  59. get_post_meta slowing down my page load (in a plugin)
  60. New WP_Query loop in admin causes problems
  61. echo a specific meta_key queried through a custom post
  62. How to increase load time of an archive/search page (WP_Query)
  63. get_post_meta in WP_Query
  64. Which is faster wpdb & get_row or wp_query & ge_post_meta?
  65. Hide posts with meta key in WP_Query
  66. Filter posts by comparing custom meta value against postdate
  67. WordPress query posts with multiple post_meta data
  68. WP_Query – Accessing MetaValue from Query Result
  69. Why can my filter query SOME metadata but not other metadata?
  70. Query against multiple locations within single custom post type post
  71. update_post_meta performance in a loop woocommerce
  72. update_post_meta performance in a loop woocommerce
  73. How to set meta_query if get_post_meta returns nested array for that key? [duplicate]
  74. I need query_posts() to order results first by a meta value and then by post ID
  75. Look for string in posts and postmeta
  76. Query postmeta based on meta_value, return array of post_id
  77. update_post_meta() not updating
  78. I can’t get post based on its postmeta value and key
  79. Saving custom fields for WP_Query to retrieve
  80. Meta key in wp_query bug?
  81. How to show all the associated posts with specific date of data metabox?
  82. Get a page ancestor from a most viewed list
  83. WP Meta Query at depth 2
  84. WP_Query with child element
  85. Sort by meta key within same day
  86. WP_Query Posts by Metadata from Option Tree
  87. Sorting Posts with meta value not working
  88. How to get several fields from wp_query?
  89. WP Query to order posts by multiple meta fields
  90. Return a single custom post from multiple meta queries
  91. Custom Search Query – include only custom fields and title
  92. How to count post meta key values for all posts in database
  93. How to query post ids liked by the Author
  94. loop through custom post types with meta data
  95. query by meta value then date and not empty meta value
  96. wordpress sorting using array merge by price in ascending order but price with 0 must be show last
  97. Query posts by meta value and sort by another meta key
  98. WP_Query by meta key not returning any posts
  99. Extend search query to search meta keys values based on search string
  100. How to get posts that have certain meta key value and order based on another meta key’s value
Categories wp-query Tags popular-posts, post-meta, wp-query
Display height and width properties with the_post_thumbnail() or related function
Why use %d in php when in function

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress