moving artisans filters into a dedicated file
This commit is contained in:
parent
e7a80da6aa
commit
ebf1b0d41c
392
includes/artisans-columns-filters.php
Normal file
392
includes/artisans-columns-filters.php
Normal file
|
|
@ -0,0 +1,392 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function remove_rank_math_seo_column_for_artisans($columns)
|
||||||
|
{
|
||||||
|
if (isset($columns['rank_math_seo_details'])) {
|
||||||
|
unset($columns['rank_math_seo_details']);
|
||||||
|
}
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Appliquer le filtre uniquement pour le post type "artisans"
|
||||||
|
add_filter('manage_artisans_posts_columns', 'remove_rank_math_seo_column_for_artisans', 20);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ACF SAVE POST
|
||||||
|
function save_acf_post_mdp_status($post_id)
|
||||||
|
{
|
||||||
|
$mdp_status = get_field('mdp_status', $post_id);
|
||||||
|
if ($mdp_status) {
|
||||||
|
update_post_meta($post_id, 'mdp_status_meta', $mdp_status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('acf/save_post', 'save_acf_post_mdp_status');
|
||||||
|
|
||||||
|
// // apply the abose meta setting for all posts
|
||||||
|
// function apply_acf_post_mdp_status_for_all_posts()
|
||||||
|
// {
|
||||||
|
// $posts = get_posts(array(
|
||||||
|
// 'post_type' => 'artisans',
|
||||||
|
// 'numberposts' => -1
|
||||||
|
// ));
|
||||||
|
// foreach ($posts as $post) {
|
||||||
|
// save_acf_post_mdp_status($post->ID);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// add_action('init', 'apply_acf_post_mdp_status_for_all_posts');
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// **** AJOUT DES COLONNES
|
||||||
|
function metiers_patrimoine_artisans_add_acf_posts_columns($columns)
|
||||||
|
{
|
||||||
|
global $current_screen;
|
||||||
|
|
||||||
|
// SUPPRIMER LA COLONNE 'date'
|
||||||
|
if (isset($columns['date'])) {
|
||||||
|
unset($columns['date']);
|
||||||
|
}
|
||||||
|
$customColumns = array(
|
||||||
|
'metiers' => 'Métiers',
|
||||||
|
'elements' => 'Éléments du bâtiment',
|
||||||
|
'conseiller' => 'Conseiller',
|
||||||
|
'mdpstatus' => 'Statut',
|
||||||
|
'lastmodified' => 'Dernière modification',
|
||||||
|
'onlinedate' => 'Mise en ligne'
|
||||||
|
);
|
||||||
|
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + $customColumns + array_slice($columns, 2, count($columns) - 2, true);
|
||||||
|
return array_merge($new_admin_col_arrays);
|
||||||
|
}
|
||||||
|
add_filter('manage_artisans_posts_columns', 'metiers_patrimoine_artisans_add_acf_posts_columns');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
GESTION DE LA VALEUR DE CHAQUE COLONNE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
|
||||||
|
{
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
|
||||||
|
if ($column == 'conseiller') {
|
||||||
|
$conseiller = get_field('conseiller', $post_id);
|
||||||
|
if (!isset($conseiller)) return;
|
||||||
|
|
||||||
|
$conseillerDatas = get_userdata($conseiller);
|
||||||
|
if (!isset($conseillerDatas->display_name)) return;
|
||||||
|
|
||||||
|
echo $conseillerDatas->display_name;
|
||||||
|
}
|
||||||
|
if ($column == 'mdpstatus') {
|
||||||
|
// $status = get_field('mdp_status', $post_id);
|
||||||
|
// if (!$status || !isset($status['label'])) return;
|
||||||
|
$status_meta = get_post_meta($post_id, 'mdp_status_meta', true);
|
||||||
|
if (!$status_meta || !isset($status_meta['label'])) return;
|
||||||
|
echo '<div class="status-state status-state--' . $status_meta['value'] . '">' . $status_meta['label'] . '</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if ($column == 'metiers') {
|
||||||
|
$terms = get_the_terms($post_id, 'metiers');
|
||||||
|
if ($terms) {
|
||||||
|
$parent_terms = array_filter($terms, function ($term) {
|
||||||
|
return $term->parent == 0;
|
||||||
|
});
|
||||||
|
// if (empty($parent_terms)) {
|
||||||
|
// echo '<p class="no-results">Aucun métier parent</p>';
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
echo '<div class="admin-column-metiers-container">';
|
||||||
|
foreach ($terms as $term) {
|
||||||
|
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
||||||
|
echo esc_html($term->name);
|
||||||
|
echo '</a>';
|
||||||
|
}
|
||||||
|
echo '</div >';
|
||||||
|
} else {
|
||||||
|
echo '<p class="no-results"> × </p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($column == 'elements') {
|
||||||
|
$terms = get_the_terms($post_id, 'elementsbatiments');
|
||||||
|
if ($terms) {
|
||||||
|
$parent_terms = array_filter($terms, function ($term) {
|
||||||
|
return $term->parent == 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
echo '<div class="admin-column-metiers-container">';
|
||||||
|
foreach ($terms as $term) {
|
||||||
|
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
||||||
|
echo esc_html($term->name);
|
||||||
|
echo '</a>';
|
||||||
|
}
|
||||||
|
echo '</div >';
|
||||||
|
} else {
|
||||||
|
echo '<p class="no-results"> × </p>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($column == 'lastmodified') {
|
||||||
|
// $last_modified_date = get_the_modified_date('j F Y \à H:i', $post_id);
|
||||||
|
$last_modified_date = get_the_modified_date('d/m/Y', $post_id);
|
||||||
|
if (!$last_modified_date) return;
|
||||||
|
echo $last_modified_date;
|
||||||
|
}
|
||||||
|
if ($column == 'onlinedate') {
|
||||||
|
$published_date = get_the_date('d/m/Y', $post_id);
|
||||||
|
if (!$published_date) return;
|
||||||
|
echo $published_date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_handle_posts_custom_columns', 10, 2);
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
GESTION DU FILTRAGE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
// **** CREATION DES DROPDOWN SELECT DE FILTRAGE
|
||||||
|
function metiers_patrimoine_filter_posts_declare_dropdowns()
|
||||||
|
{
|
||||||
|
global $typenow;
|
||||||
|
global $wp_meta_boxes;
|
||||||
|
// global $pagenow;
|
||||||
|
|
||||||
|
// write_log($wp_meta_boxes);
|
||||||
|
|
||||||
|
$post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post';
|
||||||
|
if ($post_type !== 'artisans') return;
|
||||||
|
|
||||||
|
$metiers_by_parent = getAllMetiersTermsByParents();
|
||||||
|
$batiments_by_parent = getAllBatimentsTermsByParents();
|
||||||
|
$conseillers = get_users();
|
||||||
|
|
||||||
|
// $mdp_status_field = get_field_object('mdp_status');
|
||||||
|
// $mdp_status_choices = isset($mdp_status_field['choices']) ? $mdp_status_field['choices'] : array();
|
||||||
|
$mdp_status_datar = acf_get_field("mdp_status",);
|
||||||
|
$mdp_status_datas = get_field_object("mdp_status");
|
||||||
|
// write_log($typenow);
|
||||||
|
// write_log($mdp_status_datar);
|
||||||
|
// write_log($mdp_status_datas);
|
||||||
|
|
||||||
|
$mdp_status_choices = isset($mdp_status_datas['choices']) ? $mdp_status_datas['choices'] : null;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// write_log($mdp_status_choices);
|
||||||
|
|
||||||
|
$meta_key = 'mdp_status';
|
||||||
|
$values = get_posts([
|
||||||
|
'post_type' => 'artisans',
|
||||||
|
'posts_per_page' => -1,
|
||||||
|
'meta_key' => $meta_key,
|
||||||
|
'fields' => 'ids',
|
||||||
|
]);
|
||||||
|
// $test = [];
|
||||||
|
// foreach ($values as $post_id) {
|
||||||
|
// $value = get_field('mdp_status', $post_id);
|
||||||
|
// if (!$value) continue;
|
||||||
|
// $test[] = $value['value'];
|
||||||
|
// }
|
||||||
|
// $unique_values = array_unique($test);
|
||||||
|
// write_log($unique_values);
|
||||||
|
|
||||||
|
$unique_values = array_reduce(array_filter(array_map(
|
||||||
|
fn($post_id) => get_field('mdp_status', $post_id) ?? null,
|
||||||
|
$values
|
||||||
|
)), function ($acc, $item) {
|
||||||
|
if (isset($item['value'], $item['label'])) {
|
||||||
|
$acc[$item['value']] = $item['label'];
|
||||||
|
}
|
||||||
|
return $acc;
|
||||||
|
}, []);
|
||||||
|
// write_log("unique_values");
|
||||||
|
// write_log($unique_values);
|
||||||
|
|
||||||
|
|
||||||
|
// $values = array_map(fn($post_id) => get_field('mdp_status', $post_id), $values);
|
||||||
|
// write_log($values);
|
||||||
|
// $values = array_unique(array: array_map(callback: fn($post_id) => get_field($meta_key, $post_id), $values));
|
||||||
|
?>
|
||||||
|
<select name="metiers">
|
||||||
|
<option value="" class="please-select"><?php _e('Métier', 'metiers-patrimoine-theme'); ?></option>
|
||||||
|
<?php
|
||||||
|
$is_current = isset($_GET['metiers']) ? $_GET['metiers'] : '';
|
||||||
|
foreach ($metiers_by_parent as $index => $parent_term_data) {
|
||||||
|
$parent_term = $parent_term_data['term'];
|
||||||
|
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>%s</option>',
|
||||||
|
$parent_term->slug,
|
||||||
|
$parent_term->slug == $is_current ? ' selected="selected"' : '',
|
||||||
|
$parent_term->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select name="elementsbatiments">
|
||||||
|
<option value="" class="please-select"><?php _e('Éléments du Bâtiment', 'metiers-patrimoine-theme'); ?></option>
|
||||||
|
<?php
|
||||||
|
$is_current = isset($_GET['elementsbatiments']) ? $_GET['elementsbatiments'] : '';
|
||||||
|
foreach ($batiments_by_parent as $index => $parent_term_data) {
|
||||||
|
$parent_term = $parent_term_data['term'];
|
||||||
|
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>%s</option>',
|
||||||
|
$parent_term->slug,
|
||||||
|
$parent_term->slug == $is_current ? ' selected="selected"' : '',
|
||||||
|
$parent_term->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select name="conseiller">
|
||||||
|
<option value="" class="please-select"><?php _e('Conseiller', 'metiers-patrimoine-theme'); ?></option>
|
||||||
|
<?php
|
||||||
|
$is_current = isset($_GET['conseiller']) ? $_GET['conseiller'] : '';
|
||||||
|
foreach ($conseillers as $index => $conseiller) {
|
||||||
|
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>%s</option>',
|
||||||
|
$conseiller->ID,
|
||||||
|
$conseiller->ID == $is_current ? ' selected="selected"' : '',
|
||||||
|
$conseiller->display_name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<select name="mdpstatus">
|
||||||
|
<option value="" class="please-select"><?php _e('Statut', 'metiers-patrimoine-theme'); ?></option>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$is_current = isset($_GET['mdpstatus']) ? $_GET['mdpstatus'] : '';
|
||||||
|
foreach ($unique_values as $index => $status) {
|
||||||
|
printf(
|
||||||
|
'<option value="%s"%s>%s</option>',
|
||||||
|
$index,
|
||||||
|
$index == $is_current ? ' selected="selected"' : '',
|
||||||
|
$status
|
||||||
|
);
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</select>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('restrict_manage_posts', 'metiers_patrimoine_filter_posts_declare_dropdowns');
|
||||||
|
|
||||||
|
|
||||||
|
// **** FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
|
||||||
|
// Automatiquement géré par wordpress lorsque c'est une taxonomie
|
||||||
|
function filter_posts_by_acf_conseiller($query)
|
||||||
|
{
|
||||||
|
global $pagenow;
|
||||||
|
|
||||||
|
// Vérifier qu'on est bien dans l'admin et sur la liste des posts
|
||||||
|
if (!is_admin() || $pagenow !== 'edit.php') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vérifier qu'on est bien sur le post type 'artisans'
|
||||||
|
if (isset($_GET['post_type']) && $_GET['post_type'] !== 'artisans') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILTRE CONSEILLER
|
||||||
|
if (!empty($_GET['mdpstatus'])) {
|
||||||
|
$query->set('meta_query', [
|
||||||
|
[
|
||||||
|
'key' => 'mdp_status',
|
||||||
|
'value' => $_GET['mdpstatus'],
|
||||||
|
'compare' => '='
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILTRE CONSEILLER
|
||||||
|
if (!empty($_GET['conseiller'])) {
|
||||||
|
$query->set('meta_query', [
|
||||||
|
[
|
||||||
|
'key' => 'conseiller',
|
||||||
|
'value' => $_GET['conseiller'],
|
||||||
|
'compare' => '='
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('pre_get_posts', 'filter_posts_by_acf_conseiller');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ##########################################################
|
||||||
|
// ##########################################################
|
||||||
|
// ##########################################################
|
||||||
|
// ##########################################################
|
||||||
|
|
||||||
|
function mytheme_filter_posts_declare_dropdowns()
|
||||||
|
{
|
||||||
|
// [.. Vericications de base]
|
||||||
|
|
||||||
|
// Les données sont correctement retournées au chargement initial de la page (lorsqu’aucun filtre n’est appliqué),
|
||||||
|
// mais elles sont vides lorsque le filtre est activé.
|
||||||
|
$mdp_status_datas_object = get_field_object("mdp_status");
|
||||||
|
$mdp_status_datas = acf_get_field("mdp_status");
|
||||||
|
|
||||||
|
// [.. Boucle foreach et construction d'un dropdown]
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('restrict_manage_posts', 'mytheme_filter_posts_declare_dropdowns');
|
||||||
|
|
||||||
|
function filter_posts_by_custom_datas($query)
|
||||||
|
{
|
||||||
|
// [.. Vericications de base]
|
||||||
|
|
||||||
|
if (!empty($_GET['mdpstatus'])) {
|
||||||
|
$query->set('meta_query', [
|
||||||
|
[
|
||||||
|
'key' => 'mdp_status',
|
||||||
|
'value' => $_GET['mdpstatus'],
|
||||||
|
'compare' => '='
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
add_action('pre_get_posts', 'filter_posts_by_custom_datas');
|
||||||
|
|
||||||
|
|
||||||
|
// **** FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
|
||||||
|
function metiers_patrimoine_filter_post_by_metiers_query($query)
|
||||||
|
{
|
||||||
|
write_log("filter_post_by_metiers_query");
|
||||||
|
}
|
||||||
|
|
||||||
|
// add_filter('parse_query', 'metiers_patrimoine_filter_post_by_metiers_query');
|
||||||
|
|
||||||
|
|
||||||
|
/* ----------------------------------------------------------------------
|
||||||
|
RENDRE LES COLONNES "MISE EN LIGNE" et "DERNIÈRE MODIFICATION" TRIABLE
|
||||||
|
------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
function metiers_patrimoine_artisans_sortable_columns($columns)
|
||||||
|
{
|
||||||
|
$columns['onlinedate'] = 'onlinedate';
|
||||||
|
$columns['lastmodified'] = 'lastmodified';
|
||||||
|
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
add_filter('manage_edit-artisans_sortable_columns', 'metiers_patrimoine_artisans_sortable_columns');
|
||||||
|
|
@ -245,180 +245,4 @@ function add_last_modified_date_to_publish_box()
|
||||||
// post_submit_meta_box($post, array('side' => 'core'));
|
// post_submit_meta_box($post, array('side' => 'core'));
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
SUPPRIMER LA COLONNE RANK MATH SEO SI ELLE EST PRÉSENTE
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
function remove_rank_math_seo_column_for_artisans($columns)
|
|
||||||
{
|
|
||||||
if (isset($columns['rank_math_seo_details'])) {
|
|
||||||
unset($columns['rank_math_seo_details']);
|
|
||||||
}
|
|
||||||
return $columns;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Appliquer le filtre uniquement pour le post type "artisans"
|
|
||||||
add_filter('manage_artisans_posts_columns', 'remove_rank_math_seo_column_for_artisans', 20);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
DÉCLARATION DES COLONNES CUSTOM DANS LA LISTE DES POSTS ARTISANS
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
// **** AJOUT DES COLONNES
|
|
||||||
function metiers_patrimoine_artisans_add_acf_posts_columns($columns)
|
|
||||||
{
|
|
||||||
global $current_screen;
|
|
||||||
|
|
||||||
// SUPPRIMER LA COLONNE 'date'
|
|
||||||
if (isset($columns['date'])) {
|
|
||||||
unset($columns['date']);
|
|
||||||
}
|
|
||||||
$customColumns = array(
|
|
||||||
'metiers' => 'Métiers',
|
|
||||||
'elements' => 'Éléments du bâtiment',
|
|
||||||
'conseiller' => 'Conseiller',
|
|
||||||
'status' => 'Statut',
|
|
||||||
'lastmodified' => 'Dernière modification',
|
|
||||||
'onlinedate' => 'Mise en ligne'
|
|
||||||
);
|
|
||||||
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + $customColumns + array_slice($columns, 2, count($columns) - 2, true);
|
|
||||||
return array_merge($new_admin_col_arrays);
|
|
||||||
}
|
|
||||||
add_filter('manage_artisans_posts_columns', 'metiers_patrimoine_artisans_add_acf_posts_columns');
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
GESTION DE LA VALEUR DE CHAQUE COLONNE
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
|
|
||||||
{
|
|
||||||
|
|
||||||
$post_id = get_the_ID();
|
|
||||||
|
|
||||||
if ($column == 'conseiller') {
|
|
||||||
$conseiller = get_field('conseiller', $post_id);
|
|
||||||
if (!$conseiller) return;
|
|
||||||
echo $conseiller['user_firstname'] . ' ' . $conseiller['user_lastname'];
|
|
||||||
}
|
|
||||||
if ($column == 'status') {
|
|
||||||
$status = get_field('mdp_status', $post_id);
|
|
||||||
if (!$status || !isset($status['label'])) return;
|
|
||||||
echo '<div class="status-state status-state--' . $status['value'] . '">' . $status['label'] . '</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($column == 'metiers') {
|
|
||||||
$terms = get_the_terms($post_id, 'metiers');
|
|
||||||
if ($terms) {
|
|
||||||
$parent_terms = array_filter($terms, function ($term) {
|
|
||||||
return $term->parent == 0;
|
|
||||||
});
|
|
||||||
// if (empty($parent_terms)) {
|
|
||||||
// echo '<p class="no-results">Aucun métier parent</p>';
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
echo '<div class="admin-column-metiers-container">';
|
|
||||||
foreach ($terms as $term) {
|
|
||||||
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
|
||||||
echo esc_html($term->name);
|
|
||||||
echo '</a>';
|
|
||||||
}
|
|
||||||
echo '</div >';
|
|
||||||
} else {
|
|
||||||
echo '<p class="no-results"> × </p>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ($column == 'elements') {
|
|
||||||
$terms = get_the_terms($post_id, 'elementsbatiments');
|
|
||||||
if ($terms) {
|
|
||||||
$parent_terms = array_filter($terms, function ($term) {
|
|
||||||
return $term->parent == 0;
|
|
||||||
});
|
|
||||||
|
|
||||||
echo '<div class="admin-column-metiers-container">';
|
|
||||||
foreach ($terms as $term) {
|
|
||||||
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
|
|
||||||
echo esc_html($term->name);
|
|
||||||
echo '</a>';
|
|
||||||
}
|
|
||||||
echo '</div >';
|
|
||||||
} else {
|
|
||||||
echo '<p class="no-results"> × </p>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if ($column == 'lastmodified') {
|
|
||||||
// $last_modified_date = get_the_modified_date('j F Y \à H:i', $post_id);
|
|
||||||
$last_modified_date = get_the_modified_date('d/m/Y', $post_id);
|
|
||||||
if (!$last_modified_date) return;
|
|
||||||
echo $last_modified_date;
|
|
||||||
}
|
|
||||||
if ($column == 'onlinedate') {
|
|
||||||
$published_date = get_the_date('d/m/Y', $post_id);
|
|
||||||
if (!$published_date) return;
|
|
||||||
echo $published_date;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_handle_posts_custom_columns', 10, 2);
|
|
||||||
|
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
|
||||||
GESTION DU FILTRAGES PAR METIERS
|
|
||||||
------------------------------------------------------------------------*/
|
|
||||||
// **** CREATION DU DROPDOWN SELECT AVEC LES OPTIONS
|
|
||||||
function metiers_patrimoine_filter_posts_per_metiers_declare_dropdown()
|
|
||||||
{
|
|
||||||
global $pagenow;
|
|
||||||
$post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post';
|
|
||||||
|
|
||||||
//only add filter to post type you want
|
|
||||||
if ($post_type == 'artisans') {
|
|
||||||
$metiers_by_parent = getAllMetiersTermsByParents();
|
|
||||||
|
|
||||||
?>
|
|
||||||
<select name="metiers">
|
|
||||||
<option value=""><?php _e('Filtrer par Métier', 'metiers-patrimoine-theme'); ?></option>
|
|
||||||
<?php
|
|
||||||
$current_v = isset($_GET['metiers']) ? $_GET['metiers'] : '';
|
|
||||||
foreach ($metiers_by_parent as $index => $parent_term_data) {
|
|
||||||
$parent_term = $parent_term_data['term'];
|
|
||||||
|
|
||||||
printf(
|
|
||||||
'<option value="%s"%s>%s</option>',
|
|
||||||
$parent_term->slug,
|
|
||||||
$parent_term->slug == $current_v ? ' selected="selected"' : '',
|
|
||||||
$parent_term->name
|
|
||||||
);
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</select>
|
|
||||||
<?php
|
|
||||||
}
|
|
||||||
}
|
|
||||||
add_action('restrict_manage_posts', 'metiers_patrimoine_filter_posts_per_metiers_declare_dropdown');
|
|
||||||
|
|
||||||
// **** FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
|
|
||||||
function metiers_patrimoine_filter_post_by_metiers_query($query)
|
|
||||||
{
|
|
||||||
global $pagenow;
|
|
||||||
$type = 'artisans'; // change to custom post name.
|
|
||||||
if (isset($_GET['post_type'])) {
|
|
||||||
$type = $_GET['post_type'];
|
|
||||||
}
|
|
||||||
if (($type === 'artisans') && is_admin() && $pagenow == 'edit.php' && isset($_GET['metiers']) && $_GET['metiers'] != '') {
|
|
||||||
$query->query_vars['tax_query'] = array(
|
|
||||||
array(
|
|
||||||
'taxonomy' => 'metiers',
|
|
||||||
'field' => 'slug',
|
|
||||||
'terms' => $_GET['metiers'],
|
|
||||||
'include_children' => true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
add_filter('parse_query', 'metiers_patrimoine_filter_post_by_metiers_query');
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user