這篇文章主要介紹“wordpress如何添加自定義按鈕并導出csv”,在日常操作中,相信很多人在wordpress如何添加自定義按鈕并導出csv問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對大家解答”wordpress如何添加自定義按鈕并導出csv”的疑惑有所幫助!接下來(lái),請跟著(zhù)小編一起來(lái)學(xué)習吧!
wordpress 后臺添加自定義按鈕導出csv
在wp-admin/edit.php中找到如下代碼:
<?php if ( current_user_can( $post_type_object->cap->create_posts ) ) { echo ' <a href="' . esc_url( admin_url( $post_new_file ) ) . '" class="page-title-action">' . esc_html( $post_type_object->labels->add_new ) . '</a>'; }
在上面代碼的下一行加入如下代碼:
if ($post_type == 'aaa') { echo ' <a href="'.esc_url( admin_url('admin-ajax.php?action=export_permanent_csv')).'" class="page-title-action">CSVをエクスポート</a>'; }
$post_type 是在這個(gè)文件的頭部獲取的文章的類(lèi)型。
在wp-content/themes/hcr/functions/admin.php
function export_permanent_csv() { $args = array( 'post_type' => 'aaa', 'numberposts' => -1, 'meta_key' => 'mark_id', 'orderby' => 'meta_value_num', 'order' => 'ASC', ); $posts = get_posts($args); if (empty($posts)) { return; } $noNumber = 1; foreach ($posts as $post) { $metaData = get_post_meta($post->ID); $data = [ $metaData['mark_id'][0], $noNumber, $post->post_title, $metaData['prmnnt_address'][0], $metaData['prmnnt_tel'][0], $metaData['prmnnt_fax'][0], $metaData['prmnnt_site'][0], $metaData['prmnnt_time'][0], $metaData['prmnnt_closing'][0], $metaData['prmnnt_service'][0], $metaData['prmnnt_class'][0], $post->post_type, ]; $csv_output .= '"'.implode('","', $data).'"'."\n"; $noNumber++; } $csv_output .= "\n"; $filename = $file."_".date("Ymd", time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header("Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; } add_action('wp_ajax_export_permanent_csv', 'export_permanent_csv');
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自本網(wǎng)站內容采集于網(wǎng)絡(luò )互聯(lián)網(wǎng)轉載等其它媒體和分享為主,內容觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如侵犯了原作者的版權,請告知一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容,聯(lián)系我們QQ:712375056,同時(shí)歡迎投稿傳遞力量。
Copyright ? 2009-2022 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 特網(wǎng)科技 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 百度云 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站