-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtaxfilteringbackend.php
More file actions
102 lines (94 loc) · 3.98 KB
/
taxfilteringbackend.php
File metadata and controls
102 lines (94 loc) · 3.98 KB
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
<?php
//FILTRI
add_action( 'restrict_manage_posts', function() {
global $typenow;
$taxonomy = 'ditte';
if ($typenow == 'avcp') {
$filters = array($taxonomy);
foreach ($filters as $tax_slug) {
$tax_obj = get_taxonomy($tax_slug);
$tax_name = $tax_obj->labels->name;
$terms = get_terms($tax_slug);
echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
echo "<option value=''>Tutte le ditte</option>";
foreach ($terms as $term) {
$label = (isset($_GET[$tax_slug])) ? $_GET[$tax_slug] : ''; // Fix
echo '<option value='. $term->slug, $label == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
}
echo "</select>";
}
}
$taxonomy = 'annirif';
if ($typenow == 'avcp') {
$filters = array($taxonomy);
foreach ($filters as $tax_slug) {
$tax_obj = get_taxonomy($tax_slug);
$tax_name = $tax_obj->labels->name;
$terms = get_terms($tax_slug);
echo "<select name='$tax_slug' id='$tax_slug' class='postform'>";
echo "<option value=''>Tutti gli Anni di Riferimento</option>";
foreach ($terms as $term) {
$label = (isset($_GET[$tax_slug])) ? $_GET[$tax_slug] : ''; // Fix
echo '<option value='. $term->slug, $label == $term->slug ? ' selected="selected"' : '','>' . $term->name .' (' . $term->count .')</option>';
}
echo "</select>";
}
}
} );
add_filter( 'manage_edit-avcp_columns', function( $column ) {
$column['avcp_CIG'] = 'CIG';
$column['avcp_check'] = 'Controllo';
$column['date'] = 'Data pubblicazione sul sito';
return $column;
} );
function avcp_modify_post_table_row( $column_name, $post_id ) {
$custom_fields = get_post_custom( $post_id );
switch ($column_name) {
case 'avcp_CIG' :
if ( isset($custom_fields['avcp_cig'][0]) ) {
echo $custom_fields['avcp_cig'][0];
} else {
echo '<center><font style="background-color:red;color:white;padding:2px;border-radius:3px;font-weight:bold;">Nessuno</font></center>';
}
break;
case 'avcp_check' :
$checkok = 0;
$dittepartecipanti = get_the_terms( $post_id, 'ditte' );
$cats = get_post_meta($post_id,'avcp_aggiudicatari',true);
if(is_array($dittepartecipanti)) {
foreach ($dittepartecipanti as $term) {
$cterm = get_term_by('name',$term->name,'ditte');
$cat_id = $cterm->term_id; //Prende l'id del termine
$term_meta = get_option( "taxonomy_$cat_id" );
$term_return = esc_attr( $term_meta['avcp_codice_fiscale'] );
$checked = (in_array($cat_id,(array)$cats)? ' checked="checked"': "");
if ($checked) {
echo $term->name . ', ';
$checkok++;
}
}
}
if ($checkok == 0) {
echo '<font style="background-color:red;color:white;padding:2px;border-radius:3px;font-weight:bold;">Aggiudicatari mancanti</font>';
}
break;
default:
}
}
add_filter( 'manage_posts_custom_column', 'avcp_modify_post_table_row', 10, 2 );
function my_sortable_cake_column( $columns ) {
$column['avcp_CIG'] = 'CIG';
$column['avcp_AGG'] = 'AGG';
return $columns;
}
add_filter( 'manage_edit-cake_sortable_columns', 'my_sortable_cake_column' );
/*
* ADMIN COLUMN - SORTING - MAKE HEADERS SORTABLE
* https://gist.github.com/906872
*/
add_filter("manage_edit-avcp_sortable_columns", 'avcp_date_sort');
function avcp_date_sort($columns) {
$column['avcp_CIG'] = 'CIG';
return $column;
}
?>