-
Notifications
You must be signed in to change notification settings - Fork 0
/
Template.php
79 lines (65 loc) · 1.73 KB
/
Template.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
77
78
79
<?php
/**
* Global functions that can be used in templates.
*
* @package Upstatement\Editorial
*/
namespace Upstatement\Editorial;
use Upstatement\Editorial\Taxonomy\Author;
use WP_Post;
use WP_Term;
/**
* Allow themes to retrieve a list of authors for a given post.
*
* @param WP_Post|int $post Optional post to retrieve authors for. Leave blank to use the current global post.
* @param string $field The field to return for each author. This can be any property from a WP_Term.
*
* @return array<WP_Term>|null List of author terms.
*/
function get_post_authors( $post = null, $field = null ) {
$post = get_post( $post );
if ( ! $post ) {
return null;
}
$authors = array();
$author_ids = get_post_meta( $post->ID, Author::AUTHOR_META_KEY, true );
if ( is_array( $author_ids ) && count( $author_ids ) > 0 ) {
$authors = get_terms(
array(
'taxonomy' => Taxonomy\Author::NAME,
'object_ids' => $post->ID,
'include' => $author_ids,
'orderby' => 'include',
)
);
if ( ! is_array( $authors ) ) {
return null;
}
}
if ( $field ) {
return wp_list_pluck( $authors, $field );
}
return $authors;
}
/**
* Helper function for themes to retrieve overline category a given post.
*
* @param WP_Post|int $post Post to retrieve the overline for. Optional. Leave blank to use the current global post.
*
* @return WP_Term|null Category used as overline
*/
function get_post_overline( $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return null;
}
$category_id = get_post_meta( $post->ID, 'topper_overline', true );
if ( ! $category_id ) {
return null;
}
$category = get_category( $category_id );
if ( ! $category instanceof WP_Term ) {
return null;
}
return $category;
}