WordPress php post stats
New here? Learn about Bountify and follow @bountify to get notified of new bounties! x

Hi there,

I would like a graph of all the posts made in the past 30 days.

<?php $post_ids = get_posts(array(
$args, //Your arguments
'post_type' => 'wa_pns',
'posts_per_page'=> -1,
'fields' => 'ids,post_date',
'meta_query' => array(
array(
'key' => '_wapn',
'value' => 'post',
'compare' => 'LIKE'
)
) // Only get post IDs
));
?>

And for the graph we will need to use the google graph API
Something like this but better :)

https://developers.google.com/chart/interactive/docs/gallery/linechart

` <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js >
<script type="text/javascript" >
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Day', 'posts'],
      ['1',  1000],
      ['2',  1170],
      ['3',  660],
      ['4',  1030],
      ['5',  660],
    .......
      ['31',  1030]
    ]);

    var options = {
      title: 'App Performance',
      curveType: 'function',
      legend: { position: 'bottom' }
    };

    var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

    chart.draw(data, options);
  }
</script>`

`

                         <div id="curve_chart" style="width: 100%; height: 500px"></div>`                       

Results from PHP print_r

`Array
(
[0] => WP_Post Object
(
[ID] => 58
[post_author] => 1
[post_date] => 2017-01-05 14:07:13
[post_date_gmt] => 2017-01-05 14:07:13
[post_content] => android
[post_title] => ZVJ2OUs1emJSWVE6QVBBOTFiR1k1Yml5MXpnVWVSM0ZlS0I3MUdNam4xTFkza0RHVF82b1daRG0wUVlQdnhvRGVBMjJYS2FZSWN2Mm1KRy1jTUg5UWhNX2N6M01oUzFSQkwxVFZGNF9RTWJNUXBQQUpnQnljellRYlc1eE1yRGhOTUE4eHZEay1obEptOUNpSjJ0RDBERjk=
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => zvj2ous1emjswve6qvbbotfir1k1yml5mxpnvwvsm0zls0i3mudnam4xtfkza0rhvf82b1darg0wuvlqdnhvrgvbmjjys2fzswn2mm1kry1jtug5uwhnx2n6m01ouzfsqkwxvfzgnf9rtwjnuxbqqupnqnljellrylc1ee1yrghotue4ehzeay1obeptounpsjj0rdbe
[to_ping] =>
[pinged] =>
[post_modified] => 2017-01-05 14:07:13
[post_modified_gmt] => 2017-01-05 14:07:13
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://192.168.1.34/appbuilder/?wa_pns=zvj2ous1emjswve6qvbbotfir1k1yml5mxpnvwvsm0zls0i3mudnam4xtfkza0rhvf82b1darg0wuvlqdnhvrgvbmjjys2fzswn2mm1kry1jtug5uwhnx2n6m01ouzfsqkwxvfzgnf9rtwjnuxbqqupnqnljellrylc1ee1yrghotue4ehzeay1obeptounpsjj0rdbe
[menu_order] => 0
[post_type] => wa_pns
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)

)`

Hey Dave, do you want the php with Worpress Functions or an independent php file ?
Subhash Dasyam 10 months ago
Using the php functions of WordPress please. I have just added the results I get from the function I posted.
davesargent 10 months ago
Sure working on it, please wait
Subhash Dasyam 10 months ago
Take your time :)
davesargent 10 months ago
Hi dave, do you want the javascript array as well ? i mean the php function which generate the count of posts for each day for past 30 days is done will that be ok ?
Subhash Dasyam 10 months ago

Crowdsource coding tasks.

2 Solutions


Hi Dave,
First, you can try Subhash Dasyam answer to get the statistics of last month posts. i check it on github and it looks perfect!

Link: https://gist.github.com/subhashdasyam/b8efaafc7fe80c0ec048f5c971ec1563

so query result of his script is like this:

array(1=>20,2=>1,....);

What i want to add is that you can use this output with canvasJS to present it as a chart. CanvasJs looks awesome and had a really good animations in charts. also written in JS JQuery. so easy to use and to implement. i always use it to display charts. you can use it to display your results.

Link: http://canvasjs.com/jquery-charts/

also, i selected one that looks sweet and can handle any design or wanted results. (example code in the link)

Link: http://canvasjs.com/editor/?id=http://canvasjs.com/example/gallery/jquery/export-feature/

Also you can relate your php array easily to draw the chart. (php output fit exactly the chart input) if you need help coding it, you can ask. i can help you doing it.

If this helped you, you can tip me! ;)

Kind regards,
Houcem B.A. Chlegou.

Thanks for that. Can you show me how to relate the results with this. Of course I will tip you.
davesargent 10 months ago
send me the chosen chart that you selected it and the php output array
Chlegou 10 months ago
when you came online, email me: nicolastsue@gmail.com
Chlegou 10 months ago

Hi dave

https://gist.github.com/subhashdasyam/b8efaafc7fe80c0ec048f5c971ec1563

the above scripts (wordpress) gets each day posts for past 30 days and stores in an array.

You can use that array any where, with D3 or Google Charts

Let me know if you need anymore help

Regards
Subhash Dasyam

PS: the output of the scripts will be as follows

Day = > Number of posts

All this in array.

PS: PS:

https://gist.github.com/subhashdasyam/776335f22650a9e147a1b55a3907585a
I have added Google Visualization example in two files do check out above link :)
Hey that's great thanks I'm going to test now.
davesargent 10 months ago
Sure :) let me know if you need any changes or help
Subhash Dasyam 10 months ago
Thanks for this amazing work again Subhash
davesargent 10 months ago
@dave anytime dave :) thanks for choosing my sol
Subhash Dasyam 10 months ago
also if you want this to load into Google Visualization chart i can help you let me write it down
Subhash Dasyam 10 months ago
@Dave Visualization added here https://gist.github.com/subhashdasyam/776335f22650a9e147a1b55a3907585a with complete example
Subhash Dasyam 10 months ago
Subhash, just one thing there is 30 days what happens if there are 31 or 28?
davesargent 10 months ago
don't worry those are automatically covered, this gets information for past 30 days from the current day. The 28 or 31 or 30 days are automatically covered
Subhash Dasyam 10 months ago
Thanks for the new example you are awesome! If you are ever looking for freelance work you can contact me :)
davesargent 10 months ago
Thanks dave :) i am always available, you already have my email, if you have any projects let me know.
Subhash Dasyam 10 months ago
View Timeline