-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.php
233 lines (189 loc) · 7.55 KB
/
functions.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
function my_theme_enqueue_styles() {
$parent_style = 'septera-style';
wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
ini_set('display_errors', 0);
ini_set('display_startup_errors',0);
/* radio button and default to unknown */
if ( !class_exists( 'WDS_Taxonomy_Radio' ) ) {
/**
* Removes and replaces the built-in taxonomy metabox with our radio-select metabox.
* @link http://codex.wordpress.org/Function_Reference/add_meta_box#Parameters
*/
class WDS_Taxonomy_Radio {
// Post types where metabox should be replaced (defaults to all post_types associated with taxonomy)
public $post_types = array();
// Taxonomy slug
public $slug = '';
// Taxonomy object
public $taxonomy = false;
// New metabox title. Defaults to Taxonomy name
public $metabox_title = '';
// Metabox priority. (vertical placement)
// 'high', 'core', 'default' or 'low'
public $priority = 'high';
// Metabox position. (column placement)
// 'normal', 'advanced', or 'side'
public $context = 'side';
// Set to true to hide "None" option & force a term selection
public $force_selection = true;
/**
* Initiates our metabox action
* @param string $tax_slug Taxonomy slug
* @param array $post_types post-types to display custom metabox
*/
public function __construct( $tax_slug, $post_types = array() ) {
$this->slug = $tax_slug;
$this->post_types = is_array( $post_types ) ? $post_types : array( $post_types );
add_action( 'add_meta_boxes', array( $this, 'add_radio_box' ) );
}
/**
* Removes and replaces the built-in taxonomy metabox with our own.
*/
public function add_radio_box() {
foreach ( $this->post_types() as $key => $cpt ) {
// remove default category type metabox
remove_meta_box( $this->slug .'div', $cpt, 'side' );
// remove default tag type metabox
remove_meta_box( 'tagsdiv-'.$this->slug, $cpt, 'side' );
// add our custom radio box
add_meta_box( $this->slug .'_radio', $this->metabox_title(), array( $this, 'radio_box' ), $cpt, $this->context, $this->priority );
}
}
/**
* Displays our taxonomy radio box metabox
*/
public function radio_box() {
// uses same noncename as default box so no save_post hook needed
wp_nonce_field( 'taxonomy_'. $this->slug, 'taxonomy_noncename' );
// get terms associated with this post
$names = wp_get_object_terms( get_the_ID(), $this->slug );
// get all terms in this taxonomy
$terms = (array) get_terms( $this->slug, 'hide_empty=0' );
// filter the ids out of the termsd
$existing = ( !is_wp_error( $names ) && !empty( $names ) )
? (array) wp_list_pluck( $names, 'term_id' )
: array();
// Check if taxonomy is hierarchical
// Terms are saved differently between types
$h = $this->taxonomy()->hierarchical;
// default value
$default_val = $h ? 0 : '';
// input name
$name = $h ? 'tax_input['. $this->slug .'][]' : 'tax_input['. $this->slug .']';
echo '<div style="margin-bottom: 5px;">
<ul id="'. $this->slug .'_taxradiolist" data-wp-lists="list:'. $this->slug .'_tax" class="categorychecklist form-no-clear">';
// If 'category,' force a selection, or force_selection is true
if ( $this->slug != 'category' && !$this->force_selection ) {
// our radio for selecting none
echo '<li id="'. $this->slug .'_tax-0"><label><input value="'. $default_val .'" type="radio" name="'. $name .'" id="in-'. $this->slug .'_tax-0" ';
checked( empty( $existing ) );
echo '> '. sprintf( __( 'No %s', 'wds' ), $this->taxonomy()->labels->singular_name ) .'</label></li>';
}
// loop our terms and check if they're associated with this post
foreach ( $terms as $term ) {
$val = $h ? $term->term_id : $term->slug;
echo '<li id="'. $this->slug .'_tax-'. $term->term_id .'"><label><input value="'. $val .'" type="radio" name="'. $name .'" id="in-'. $this->slug .'_tax-'. $term->term_id .'" ';
// if so, they get "checked"
checked( !empty( $existing ) && in_array( $term->term_id, $existing ) );
echo '> '. $term->name .'</label></li>';
}
echo '</ul></div>';
}
/**
* Gets the taxonomy object from the slug
* @return object Taxonomy object
*/
public function taxonomy() {
$this->taxonomy = $this->taxonomy ? $this->taxonomy : get_taxonomy( $this->slug );
return $this->taxonomy;
}
/**
* Gets the taxonomy's associated post_types
* @return array Taxonomy's associated post_types
*/
public function post_types() {
$this->post_types = !empty( $this->post_types ) ? $this->post_types : $this->taxonomy()->object_type;
return $this->post_types;
}
/**
* Gets the metabox title from the taxonomy object's labels (or uses the passed in title)
* @return string Metabox title
*/
public function metabox_title() {
$this->metabox_title = !empty( $this->metabox_title ) ? $this->metabox_title : $this->taxonomy()->labels->name;
return $this->metabox_title;
}
}
$custom_tax_mb = new WDS_Taxonomy_Radio( 'gender' );
}
function video_interview() {
$params = array(
'orderby' => 't.post_title ASC',
'limit' => -1,
'where' => 'video_link.meta_value != ""'
);
$mypod = pods( 'interview' , $params);
while ( $mypod -> fetch() ) {
$intervieweepod = $mypod-> field('interviewee');
$id = $intervieweepod["ID"];
$permalink = get_permalink($id);
echo '<li class="video no-bullets">' . '<a href="' . $permalink . '">' . $mypod->display('interviewee') . '</a>' . '</li>';
}
}
add_shortcode('video', 'video_interview');
function interview_location() {
$params = array(
'orderby' => 't.post_title ASC',
'limit' => -1
);
$mypod = pods( 'province' , $params);
while ( $mypod -> fetch() ) {
$id = $mypod -> field('id');
$permalink = get_permalink($id);
echo '<li class="location no-bullets">' . '<a href="' . $permalink . '">' . $mypod->display('post_title') . '</a>' . '</li>';
}
}
add_shortcode('location', 'interview_location');
function interview_topics() {
$params = array(
'orderby' => 't.post_title ASC',
'limit' => -1
);
$mypod = pods( 'story_included' , $params);
while ( $mypod -> fetch() ) {
$id = $mypod -> field('id');
$permalink = get_permalink($id);
echo '<li class="topic no-bullets">' . '<a href="' . $permalink . '">' . $mypod->display('post_title') . '</a>' . '</li>';
}
}
function load_more_posts() {
$paged = isset($_POST['paged']) ? intval($_POST['paged']) : 1;
$posts_per_page = 9; // Number of posts to load each time
$args = [
'post_type' => 'interviewee',
'post_status' => 'publish',
'posts_per_page' => $posts_per_page,
'paged' => $paged,
];
$query = new WP_Query($args);
if ($query->have_posts()) :
while ($query->have_posts()) : $query->the_post(); ?>
<div class="grid-item">
<?php echo pods('interviewee', get_the_ID())->template('Interviewee Directory'); ?>
</div>
<?php endwhile;
endif;
wp_reset_postdata();
die();
}
add_action('wp_ajax_load_more_posts', 'load_more_posts');
add_action('wp_ajax_nopriv_load_more_posts', 'load_more_posts');
add_shortcode('topics', 'interview_topics');