-
Notifications
You must be signed in to change notification settings - Fork 0
/
mf_documents_functions.php
52 lines (38 loc) · 1.29 KB
/
mf_documents_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
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
// so myfossil_documents cpt is found on assigned cat archive page
function mf_documents_query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array( 'myfossil_document', 'nav_menu_item');
$query->set('post_type',$post_type);
return $query;
}
}
add_filter('pre_get_posts', 'mf_documents_query_post_type');
// show list of categories on documents loop
function mf_documents_cats_list() {
$cat_str = '';
$args_types = array(
'type' => 'myfossil_document',
'parent' => '',
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 1,
'hierarchical' => 0,
'exclude' => '1',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => 1
);
$categories = get_categories($args_types);
foreach($categories as $category) {
$cat_str .= '<a href="' . site_url('/category/') . $category->slug . '/"/>' . $category->name . '</a> (' . $category->category_count . ')<br/>';
}
return $cat_str;
}