| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) { |
| 3 |
die; |
| 4 |
} |
| 5 |
function gvn_chart_sample_nonxml_data() |
| 6 |
{ |
| 7 |
$data['titles'] = array( |
| 8 |
'Sample: Posts by month', |
| 9 |
'Sample: Posts and non-Posts by month', |
| 10 |
'Sample: Posts by year', |
| 11 |
'Sample: Popular users/publishers' |
| 12 |
); |
| 13 |
global $wpdb; |
| 14 |
$data['sql_queries'] = array( |
| 15 |
"select count(*) postcount,SUBSTRING(`post_date`,6,2) monthnum,SUBSTRING(`post_date`,1,4) yearnum,SUBSTRING(`post_date`,1,7) monthandyear from $wpdb->posts group by monthnum,yearnum order by monthnum ", |
| 16 |
|
| 17 |
"select count(*) postcount,SUBSTRING(`post_date`,6,2) monthnum,SUBSTRING(`post_date`,1,4) yearnum,SUBSTRING(`post_date`,1,7) monthandyear from $wpdb->posts where post_type=\"post\" group by monthnum,yearnum order by monthnum ; |
| 18 |
select count(*) postcount,SUBSTRING(`post_date`,6,2) monthnum,SUBSTRING(`post_date`,1,4) yearnum,SUBSTRING(`post_date`,1,7) monthandyear from $wpdb->posts where post_type!=\"post\" group by monthnum,yearnum order by monthnum", |
| 19 |
|
| 20 |
"select count(*) postcount, SUBSTR(`post_date`,1,4) yearnum from $wpdb->posts group by yearnum order by yearnum asc limit 10 ", |
| 21 |
|
| 22 |
"select count(*) as postcount,a.post_author,b.display_name as dname |
| 23 |
from $wpdb->posts a |
| 24 |
inner join $wpdb->users b ON a.post_author=b.ID |
| 25 |
where a.post_status=\"publish\" |
| 26 |
group by a.post_author order by postcount desc limit 10" |
| 27 |
); |
| 28 |
|
| 29 |
$data['others'] = array( |
| 30 |
|
| 31 |
array( |
| 32 |
'Post count', |
| 33 |
'postcount', |
| 34 |
'Monthes', |
| 35 |
'monthandyear', |
| 36 |
500, |
| 37 |
400, |
| 38 |
'bar_l' |
| 39 |
), |
| 40 |
|
| 41 |
array( |
| 42 |
'Posts;non-Posts', |
| 43 |
'postcount', |
| 44 |
'Monthes', |
| 45 |
'monthandyear', |
| 46 |
500, |
| 47 |
400, |
| 48 |
'line_l' |
| 49 |
), |
| 50 |
|
| 51 |
array( |
| 52 |
'Post count', |
| 53 |
'postcount', |
| 54 |
'Years', |
| 55 |
'yearnum', |
| 56 |
500, |
| 57 |
400, |
| 58 |
'pie_l' |
| 59 |
), |
| 60 |
|
| 61 |
array( |
| 62 |
'Post count', |
| 63 |
'postcount', |
| 64 |
'Display name', |
| 65 |
'dname', |
| 66 |
500, |
| 67 |
400, |
| 68 |
'donut_l' |
| 69 |
) |
| 70 |
|
| 71 |
|
| 72 |
); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
foreach ($data['titles'] as $key => $value) { |
| 79 |
$args = [ |
| 80 |
'post_type' => 'gvn_schart', |
| 81 |
'title' => $value, |
| 82 |
'post_status' => 'any', // Adjust if you only want published posts |
| 83 |
'numberposts' => 1, |
| 84 |
]; |
| 85 |
|
| 86 |
$query = new WP_Query($args); |
| 87 |
$existence = $query->have_posts() ? $query->posts[0] : null; |
| 88 |
|
| 89 |
// Clean up after the query |
| 90 |
wp_reset_postdata(); |
| 91 |
|
| 92 |
|
| 93 |
if (empty($existence)) { |
| 94 |
$newid = wp_insert_post(array( |
| 95 |
'post_title' => $value, |
| 96 |
'post_type' => 'gvn_schart', |
| 97 |
'post_status' => 'private' |
| 98 |
)); |
| 99 |
add_post_meta($newid, 'guaven_sqlcharts_code', $data["sql_queries"][$key]); |
| 100 |
add_post_meta($newid, 'guaven_sqlcharts_chartwidth', $data["others"][$key][4]); |
| 101 |
add_post_meta($newid, 'guaven_sqlcharts_chartheight', $data["others"][$key][5]); |
| 102 |
add_post_meta($newid, 'guaven_sqlcharts_xarg_s', $data["others"][$key][3]); |
| 103 |
add_post_meta($newid, 'guaven_sqlcharts_xarg_l', $data["others"][$key][2]); |
| 104 |
add_post_meta($newid, 'guaven_sqlcharts_yarg_s', $data["others"][$key][1]); |
| 105 |
add_post_meta($newid, 'guaven_sqlcharts_yarg_l', $data["others"][$key][0]); |
| 106 |
add_post_meta($newid, 'guaven_sqlcharts_graphtype', $data["others"][$key][6]); |
| 107 |
|
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
} |
| 114 |
?> |
| 115 |
|