-
Notifications
You must be signed in to change notification settings - Fork 0
/
page-hub-data-export.php
76 lines (57 loc) · 2.07 KB
/
page-hub-data-export.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
$args = array(
'post_type' => 'initiatives',
'posts_per_page' => -1,
'post_status' => 'publish',
'tax_query' => array(
array(
'taxonomy' => 'hub',
'terms' => get_query_var('hub_id')
),
)
);
$posts = get_posts($args);
?>
<?php session_start();
$export_data[] = ["Name", "Status", "Hub", "Country", "Last Healthcheck Date", "Topics", "Private Email", "Email Address", "Website URL", "Twitter", "Facebook", "Instagram", "Youtube"];
foreach ($posts as $post) {
$data = get_initiative_by_id($post->ID);
$name = $data['title'];
$status = $data['status'];
$hub = $data['hub_name'];
$country = $data['country_name'];
$healthcheck_args = array(
'post_type' => 'healthchecks',
'title' => $post->ID,
'posts_per_page' => 1,
'orderby' => 'post_date',
'order' => 'DESC'
);
$latest_healthcheck = '';
$latest_healthcheck_post = get_posts($healthcheck_args);
if($latest_healthcheck_post) {
$latest_healthcheck = $latest_healthcheck_post[0]->post_date;
}
$topics = get_the_terms($post, 'topic');
$topic_output = '';
if($topics) {
$topic_list = array();
foreach($topics as $topic) {
$topic_list[] = $topic->name;
}
$topic_output = implode(', ', $topic_list);
}
$private_email = get_field('private_email', $post->ID);
$email = get_field('email', $post->ID);
$address = get_field('address_line_1', $post->ID);
$city = get_field('city', $post->ID);
$province = get_field('province', $post->ID);
$postal_code = get_field('postal_code', $post->ID);
$website = get_field('website', $post->ID);
$twitter = get_field('twitter', $post->ID);
$facebook = get_field('facebook', $post->ID);
$instagram = get_field('instagram', $post->ID);
$youtube = get_field('youtube', $post->ID);
$export_data[] = [$name, $status, $hub, $country, $latest_healthcheck, $topic_output, $private_email, $email, $address, $city, $province, $postal_code, $website, $twitter, $facebook, $instagram, $youtube];
} ?>
<?php outputCsv(date('Ymd') . '_' . $data['hub_slug'] . '_Initiative_Export.csv', $export_data); ?>