我创建了一个名为“cliente_finale”的自定义帖子类型。
我有一些自定义字段,一切正常。
我在“edit.php”中进行自定义过滤时遇到了麻烦。
我已经创建了 2 个自定义过滤器,如果单独使用或与其他所有默认 WordPress 过滤器一起使用,它们可以正常工作。但是当它们一起使用时,我只能看到最后的过滤结果(按钩子优先级排序)。
我认为我的查询结果在某种程度上被“最后一个”(优先级)过滤器覆盖。
我没有找到解决方案,可能是因为缺少 WordPress 核心功能。
这是此过滤器的代码...
/* =======================================
FILTRO COMM. PRINCIPALE
======================================= */
function list_filter_principale_cliente_finale(){
$type = 'cliente_finale';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
//only add filter to post type you want
if ('cliente_finale' == $type){
//change this to the list of values you want to show
//in 'label' => 'value' format
global $wpdb;
$all_commerciali = $wpdb->get_results( "SELECT meta_value FROM wp_postmeta WHERE meta_key = 'cliente-finale-commerciale-principale-commerciale_principale_commerciale_principale' " );
$values = array();
foreach($all_commerciali as $principale){
$principaleID = $principale->meta_value;
$principaleNome = get_user_meta($principaleID,'nickname',true);
if(!in_array($principaleID, $values)){
$values[$principaleNome] = $principaleID;
}
}
ksort($values);
?>
<select name="principale">
<option value=""><?php _e('Tutti i principali ', 'wose45436'); ?></option>
<?php
$current_v = isset($_GET['principale'])? $_GET['principale']:'';
foreach ($values as $label => $value) {
printf
(
'<option value="%s"%s>%s</option>',
$value,
$value == $current_v? ' selected="selected"':'',
$label
);
}
?>
</select>
<?php
}
}
add_action( 'restrict_manage_posts', 'list_filter_principale_cliente_finale' );
/**
* if submitted filter by post meta
*
* make sure to change META_KEY to the actual meta key
* and POST_TYPE to the name of your custom post type
*/
function filtra_principale_cliente_finale( $vars ){
global $pagenow;
$type = 'cliente_finale';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if(!is_administrator()){
$_GET['principale'] = get_current_user_id();
}
if ( 'cliente_finale' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['principale']) && $_GET['principale'] != '') {
$vars['meta_key'] = 'cliente-finale-commerciale-principale-commerciale_principale_commerciale_principale';
$vars['meta_value'] = $_GET['principale'];
}
return $vars;
}
add_filter( 'request', 'filtra_principale_cliente_finale' ,2);
/* =======================================
FILTRO COMM. PRINCIPALE - END
======================================= */
/* =======================================
FILTRO COMM. PRINCIPALE STATUS APPROVATO
======================================= */
function list_filter_principale_cliente_finale_approvato(){
$type = 'cliente_finale';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
//only add filter to post type you want
if ('cliente_finale' == $type){
//change this to the list of values you want to show
//in 'label' => 'value' format
$values = array(
"Da approvare" => "da_approvare",
"Approvato" => "approvato",
"Non approvato" => "non_approvato"
);
?>
<select name="approvato">
<option value=""><?php _e('Tutti gli status', 'wose45436'); ?></option>
<?php
$current_v = isset($_GET['approvato'])? $_GET['approvato']:'';
foreach ($values as $label => $value) {
printf
(
'<option value="%s"%s>%s</option>',
$value,
$value == $current_v? ' selected="selected"':'',
$label
);
}
?>
</select>
<?php
}
}
add_action( 'restrict_manage_posts', 'list_filter_principale_cliente_finale_approvato' );
/**
* if submitted filter by post meta
*
* make sure to change META_KEY to the actual meta key
* and POST_TYPE to the name of your custom post type
*/
function filtra_approvato_cliente_finale( $vars ){
global $pagenow;
$type = 'cliente_finale';
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if ( 'cliente_finale' == $type && is_admin() && $pagenow=='edit.php' && isset($_GET['approvato']) && $_GET['approvato'] != '') {
$vars['meta_key'] = 'cliente-finale-approvato_approvato';
$vars['meta_value'] = $_GET['approvato'];
}
return $vars;
}
add_filter( 'request', 'filtra_approvato_cliente_finale',1 );
/* =======================================
FILTRO COMM. PRINCIPALE STATUS APPROVATO - END
======================================= */
这是 WordPress 自定义帖子类型管理区域的图像
谢谢你!