我很难在wp\\U下拉页面中排除特定帖子。排除似乎有效,但我的foreach的第一个ID始终包含在下拉列表中。。。我不明白为什么。。。
My get\\u posts查询
$exclude_posts = get_posts(array(
\'post_type\' => \'organic-pickup\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'type\',
\'field\' => \'term_id\',
\'terms\' => 72 //TODO Get all ID of taxonomy \'type\' terms where types_metabox_dropdown = types_metabox_dropdown_no
)
)
));
我的foreach,其输出格式与wp\\u dropdown\\u pages参数匹配。
foreach($exclude_posts as $exclude_post) {
$excludes[] = $exclude_post->ID;
}
$exclude = implode(\',\',$excludes);
$excluded = "\'" . $exclude . "\'";
print_r($excluded);
我的下拉列表
$ogpk_pickup_field_args = array (
\'depth\' => -1,
\'class\' => \'store-pickup form-row-wide\',
\'show_option_none\' => __( \'Choisissez le point relais où retirer votre panier\', \'organic-pickup\' ),
\'name\' => \'store_pickup\',
\'hide_empty\' => false,
// \'exclude\' => \'1074,1072,1059\',
\'exclude\' => $excluded, //TODO get excluded working please...
\'post_type\' => \'organic-pickup\',
\'value_field\' => \'ID\',
\'suppress_filters\' => true
);
wp_dropdown_pages( $ogpk_pickup_field_args );
我用“104710721059”结束一个排除行。使用此参数,下拉菜单工作正常,不显示此帖子。print\\r($已排除)显示此精确字符串。。。但在下拉参数中,它总是显示第一个ID对应的帖子。。。我完全无法理解为什么。。。有什么提示吗?
最合适的回答,由SO网友:inarilo 整理而成
在使用$exclude之前,不需要添加单引号。文字用引号括起来表示它是一个字符串,但由于$exclude已经是一个字符串变量,所以可以直接传递它。
删除$excluded,您根本不需要它,只需使用
$ogpk_pickup_field_args = array (
\'depth\' => -1,
\'class\' => \'store-pickup form-row-wide\',
\'show_option_none\' => __( \'Choisissez le point relais où retirer votre panier\', \'organic-pickup\' ),
\'name\' => \'store_pickup\',
\'hide_empty\' => false,
// \'exclude\' => \'1074,1072,1059\',
\'exclude\' => $exclude,
\'post_type\' => \'organic-pickup\',
\'value_field\' => \'ID\',
\'suppress_filters\' => true
);