![]() |
I'm looking to create a simple graph thats not too crazy; its a bar graph; base on the number of wordpress posts in each hour. So I have a lot of posts and I want to see how many each hour in a bar graph. Data would like like this for example; it may be on avg from 80 to 400 posts depends on the days. what wold be an efficient way to go about this?
Update: just to update based on Arnav's question; I just looking for the query of the db in Wordpress; I can manipulate the data after.
Timespan would be one day;
00:00 : 2
01:00 : 1
02:00 : 0
03:00 : 0
04:00 : 3
05:00 : 1
06:00 : 4
07:00 : 12
08:00 : 15
09:00 : 24
10:00 : 22
11:00 : 25
12:00 : 32
13:00 : 45
14:00 : 55
15:00 : 62
16:00 : 67
17:00 : 54
18:00 : 32
19:00 : 31
20:00 : 17
21:00 : 8
22:00 : 4
23:00 : 2
Solution - 1have you added code for the bar graph? Solution - 2Do you know how to code? If you know how to code that could be solved with a scheduled CRON event, every second check the new posts https://developer.wordpress.org/plugins/cron/scheduling-wp-cron-events/ Solution - 3this is not very efficient but it should do the job and it's easy to implement. Then you could run it once a day and store the $stats array somewhere so that then you don't have to do all the queries again every time you load the graph. the idea is to make one query for each hour, and then count the posts and add them to an array which then you can use to make the graph. p.s. in the example code I just did the query for the first hour to show how to do it. Then you'd have to repeat that query 12 times tweaking the hours range so that you count and store posts for all 12 hours) Solution - 4using mysql query approach as following:
Solution - 5I like Andrea idea, but I added some codes and wrapped they into a function that close to your need: From here you can get number of posts per hour for each day in specific month and year Solution - 6Hi, Please try the following query, It will help you This query will return all posts with posts count in their time slot, If you need to get any specific date's data, please follow the below code If you need to get data between 2 dates, please follow the below code You can replace the table name wp_posts_table with your table name. Solution - 7Hello, This code will do the trick
Solution - 8have you tried using a plugin? |
Wordpress |
Type: | Code Example |
Category: | Coding |
Sub Category: | Code Example |
Uploaded by: | Admin |
Views: | 25 |