Using WordPress ‘export_filters’ PHP action

The export_filters WordPress PHP action fires at the end of the export filters form, allowing developers to add custom export filters.

Usage

add_action('export_filters', 'your_custom_function');
function your_custom_function() {
    // your custom code here
}

Parameters

  • None

More information

See WordPress Developer Resources: export_filters

Examples

Add a custom post type to the export filters

Add a dropdown to select a custom post type for exporting.

add_action('export_filters', 'add_custom_post_type_export_filter');
function add_custom_post_type_export_filter() {
    $post_types = get_post_types(array('public' => true, '_builtin' => false), 'objects');
    foreach ($post_types as $post_type) {
        ?>
        <label><?php echo $post_type->labels->name; ?></label>
        <select name="custom_post_type_export_<?php echo $post_type->name; ?>">
            <option value="0"><?php _e('All'); ?></option>
            <?php
            $args = array(
                'post_type' => $post_type->name,
                'posts_per_page' => -1
            );
            $custom_posts = get_posts($args);
            foreach ($custom_posts as $custom_post) {
                echo '<option value="' . $custom_post->ID . '">' . $custom_post->post_title . '</option>';
            }
            ?>
        </select>
        <?php
    }
}

Add a category filter to the export filters

Allow users to filter the exported content by category.

add_action('export_filters', 'add_category_export_filter');
function add_category_export_filter() {
    $categories = get_categories();
    ?>
    <label><?php _e('Categories'); ?></label>
    <select name="export_category">
        <option value="0"><?php _e('All'); ?></option>
        <?php
        foreach ($categories as $category) {
            echo '<option value="' . $category->term_id . '">' . $category->name . '</option>';
        }
        ?>
    </select>
    <?php
}

Add a custom taxonomy filter to the export filters

Allow users to filter exported content by a custom taxonomy.

add_action('export_filters', 'add_custom_taxonomy_export_filter');
function add_custom_taxonomy_export_filter() {
    $taxonomies = get_taxonomies(array('_builtin' => false), 'objects');
    foreach ($taxonomies as $taxonomy) {
        $terms = get_terms($taxonomy->name);
        ?>
        <label><?php echo $taxonomy->labels->name; ?></label>
        <select name="custom_taxonomy_export_<?php echo $taxonomy->name; ?>">
            <option value="0"><?php _e('All'); ?></option>
            <?php
            foreach ($terms as $term) {
                echo '<option value="' . $term->term_id . '">' . $term->name . '</option>';
            }
            ?>
        </select>
        <?php
    }
}

Add a date range filter to the export filters

Allow users to filter exported content by a date range.

add_action('export_filters', 'add_date_range_export_filter');
function add_date_range_export_filter() {
    ?>
    <label><?php _e('Date Range'); ?></label>
    <input type="date" name="export_date_start">
    <input type="date" name="export_date_end">
    <?php
}