使自定义分类查询在此函数中工作时出现问题。$筛选器中填充了数据,但get\\u posts()不使用它?查询在没有tax\\u查询的情况下工作,并且有:具有正确分类法的自定义帖子(列表)。。。想要我失踪吗?
add_action( \'restrict_manage_posts\', \'add_export_button\' );
function add_export_button() {
$screen = get_current_screen();
if (isset($screen->parent_file) && (\'edit.php?post_type=certificate\'==$screen->parent_file)) {
?>
<input type="submit" name="export_all_posts" id="export_all_posts" class="button button-primary" value="Export All Posts">
<script type="text/javascript">
jQuery(function($) {
$(\'#export_all_posts\').insertAfter(\'#post-query-submit\');
});
</script>
<?php
}
}
add_action( \'init\', \'func_export_all_posts\' );
function func_export_all_posts() {
if(isset($_GET[\'export_all_posts\'])) {
if(isset($_GET[\'list\'])) {
$filter = strval($_GET[\'list\']);
};
$arg = array(
\'post_type\' => \'certificate\',
\'post_status\' => \'publish\',
\'posts_per_page\' => -1,
\'tax_query\' => array(
array(
\'taxonomy\' => \'list\',
\'field\' => \'slug\',
\'terms\' => $filter ,
)
),
);
global $post;
$arr_post = get_posts($arg);
if ($arr_post) {
header(\'Content-type: text/csv\');
header(\'Content-Disposition: attachment; filename="wp.csv"\');
header(\'Pragma: no-cache\');
header(\'Expires: 0\');
$file = fopen(\'php://output\', \'w\');
fputcsv($file, array(\'Post Title\', \'URL\'));
foreach ($arr_post as $post) {
setup_postdata($post);
fputcsv($file, array(get_the_title(), get_the_permalink()));
}
exit();
}
}
}