微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在 CSV 上导出 wordpress 用户 slug?

如何解决如何在 CSV 上导出 wordpress 用户 slug?


我正在使用此代码(原始代码 [此处][1])在帖子后端创建一个按钮,以便导出和下载包含以下信息的 CSV:“帖子标题”、“URL”、“类别”、“标签','作者','Author slug' 但 我找不到导出用户 slug 的方法
我该怎么做?我很感激你的帮助
function admin_post_list_add_export_button( $which ) {
    global $typeNow;
  
    if ( 'post' === $typeNow && 'top' === $which ) {
        ?>
        <input type="submit" name="export_all_posts" class="button button-primary" value="<?PHP _e('Export All Posts'); ?>" />
        <?PHP
    }
}
 
add_action( 'manage_posts_extra_tablenav','admin_post_list_add_export_button',20,1 );

function func_export_all_posts() {
    if(isset($_GET['export_all_posts'])) {
        $arg = array(
            'post_type' => 'post','post_status' => 'publish','posts_per_page' => -1,);
  
        global $post;
        $arr_post = get_posts($arg);
        if ($arr_post) {
  
            header('Content-type: text/csv');
            header('Content-disposition: attachment; filename="wp-posts.csv"');
            header('Pragma: no-cache');
            header('Expires: 0');
  
            $file = fopen('PHP://output','w');
  
            fputcsv($file,array('Post Title','URL','Categories','Tags','Author','Author slug'));
  
            foreach ($arr_post as $post) {
                setup_postdata($post);
                  
                $categories = get_the_category();
                $cats = array();
                if (!empty($categories)) {
                    foreach ( $categories as $category ) {
                        $cats[] = $category->name;
                    }
                }
  
                $post_tags = get_the_tags();
                $tags = array();
                if (!empty($post_tags)) {
                    foreach ($post_tags as $tag) {
                        $tags[] = $tag->name;
                    }
                }
  
                fputcsv($file,array(get_the_title(),get_the_permalink(),implode(",",$cats),$tags),get_the_author(),get_user_by('slug','nicename')));
            }
  
            exit();
        }
    }
}
 
add_action( 'init','func_export_all_posts' );

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。