-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.php
68 lines (50 loc) · 1.32 KB
/
helpers.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
<?php
function wpille_pluginUrl($path = '') {
return plugin_dir_url(__FILE__) . $path;
}
function get_post_table_columns() {
global $wpdb;
$query = "
DESCRIBE " . $wpdb->prefix . "posts
";
$column = array();
foreach($wpdb->get_results($query) as $row)
$columns[] = $row->Field;
return $columns;
}
function get_post_meta_keys() {
global $wpdb;
$query = "
SELECT
meta_key as `key`,
p.post_type
FROM
" . $wpdb->prefix . "postmeta meta
INNER JOIN
" . $wpdb->prefix . "posts p ON p.ID = meta.post_id
GROUP BY
meta.meta_key
";
$meta_keys = array();
foreach($wpdb->get_results($query) as $meta)
$meta_keys[] = $meta->key;
return $meta_keys;
}
function get_taxonomies_as_array() {
$taxonomies = array();
foreach(get_taxonomies() as $name)
$taxonomies[] = $name;
return $taxonomies;
}
function wpille_keyToReadable($string) {
//return mb_convert_case(str_replace(['-', '_'], ' ', $string), MB_CASE_TITLE, "UTF-8");
return ucfirst(trim(str_replace(['-', '_'], ' ', $string)));
}
function get_post_terms_from_data($data_source, $taxonomy, $post_id) {
$post_terms = array();
foreach ($data_source as $data) {
if($data->object_id == $post_id && $data->taxonomy == $taxonomy)
$post_terms[$data->slug] = $data->name;
}
return $post_terms;
}