search
HomeCMS TutorialWordPressDetailed explanation of how to add custom buttons and export csv in wordpress

The following tutorial column of WordPress will introduce to you how to add custom buttons and export csv in the WordPress background. I hope it will be helpful to friends in need!

Detailed explanation of how to add custom buttons and export csv in wordpress

Wordpress background adds a custom button to export csv

Find the following code in wp-admin/edit.php :

<?php if ( current_user_can( $post_type_object->cap->create_posts ) ) {
    echo ' <a>' . esc_html( $post_type_object->labels->add_new ) . '</a>';
}

Add the following code to the next line of the above code:

if ($post_type == 'aaa') {
    echo ' <a>CSVをエクスポート</a>';
}

$post_type is the type of article obtained from the header of this file.
In 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');

The above is the detailed content of Detailed explanation of how to add custom buttons and export csv in wordpress. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:wordpress. If there is any infringement, please contact admin@php.cn delete
How does WordPress compare to other popular CMS platforms?How does WordPress compare to other popular CMS platforms?May 02, 2025 am 12:18 AM

WordPressexcelsineaseofuseandadaptability,makingitidealforbeginnersandsmalltomedium-sizedbusinesses.1)EaseofUse:WordPressisuser-friendly.2)Security:Drupalleadswithstrongsecurityfeatures.3)Performance:GhostoffersexcellentperformanceduetoNode.js.4)Scal

Can you use WordPress to build a membership site?Can you use WordPress to build a membership site?May 01, 2025 am 12:08 AM

Yes,youcanuseWordPresstobuildamembershipsite.Here'show:1)UsepluginslikeMemberPress,PaidMemberSubscriptions,orWooCommerceforusermanagement,contentaccesscontrol,andpaymenthandling.2)Ensurecontentprotectionwithupdatedpluginsandadditionalsecuritymeasures

Does WordPress require coding knowledge to use as a CMS?Does WordPress require coding knowledge to use as a CMS?Apr 30, 2025 am 12:03 AM

You don't need programming knowledge to use WordPress, but mastering programming can improve the experience. 1) Use CSS and HTML to adjust the theme style. 2) PHP knowledge can edit topic files and add functions. 3) Custom plug-ins and meta tags can optimize SEO. 4) Pay attention to backup and use of sub-topics to prevent update issues.

What are the security considerations when using WordPress?What are the security considerations when using WordPress?Apr 29, 2025 am 12:01 AM

TosecureaWordPresssite,followthesesteps:1)RegularlyupdateWordPresscore,themes,andpluginstopatchvulnerabilities.2)Usestrong,uniquepasswordsandenabletwo-factorauthentication.3)OptformanagedWordPresshostingorsecuresharedhostingwithawebapplicationfirewal

How does WordPress compare to other website builders?How does WordPress compare to other website builders?Apr 28, 2025 am 12:04 AM

WordPressexcelsoverotherwebsitebuildersduetoitsflexibility,scalability,andopen-sourcenature.1)It'saversatileCMSwithextensivecustomizationoptionsviathemesandplugins.2)Itslearningcurveissteeperbutofferspowerfulcontroloncemastered.3)Performancecanbeopti

5  WordPress Plugins for Developers To Use in 20255 WordPress Plugins for Developers To Use in 2025Apr 27, 2025 am 08:25 AM

Seven Must-Have WordPress Plugins for 2025 Website Development Building a top-tier WordPress website in 2025 demands speed, responsiveness, and scalability. Achieving this efficiently often hinges on strategic plugin selection. This article highlig

What would you use WordPress for?What would you use WordPress for?Apr 27, 2025 am 12:14 AM

WordPresscanbeusedforvariouspurposesbeyondblogging.1)E-commerce:WithWooCommerce,itcanbecomeafullonlinestore.2)Membershipsites:PluginslikeMemberPressenableexclusivecontentareas.3)Portfoliosites:ThemeslikeAstraallowstunninglayouts.Ensuretomanageplugins

Is WordPress good for creating a portfolio website?Is WordPress good for creating a portfolio website?Apr 26, 2025 am 12:05 AM

Yes,WordPressisexcellentforcreatingaportfoliowebsite.1)Itoffersnumerousportfolio-specificthemeslike'Astra'foreasycustomization.2)Pluginssuchas'Elementor'enableintuitivedesign,thoughtoomanycanslowthesite.3)SEOisenhancedwithtoolslike'YoastSEO',boosting

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools