Support » Plugins » Extending export to support custom field selection by plugin

  • Goal: Add field(s) to the Tools > Export menu which will allow the user to define which posts / post types should be exported based additionally on ones that have custom fields (meta key / value) attached. The larger goal is related to export/import of data from a WPML-based site into a WPMS with separate site / language.

    I have been able to:

    Add a select box to the export screen.

    add_action('export_filters', "export_language_select");
    function export_language_select() {
    		echo "<strong>" . "Language" . "</strong><br/>";
    		$languages = icl_get_languages('skip_missing=0');
    		echo "<select name='ml2msls_language_filter'>";
    		echo "<option value=''></option>";
    		foreach ($languages  as $language ) {
        		echo '<option value="' . $language['language_code'] . '" >'. $language['language_code'] . '</option>';
    		echo "</select>";

    Pass the argument to export

    add_filter('export_args', "export_language_filter_args");
    function export_language_filter_args( $args) {
    		if ( $_REQUEST['ml2msls_language_filter'] )
    			$args['ml2msls_language_filter'] = $_REQUEST['ml2msls_language_filter'];
    		return $args;

    And then…..

    add_action( 'export_wp', "export_language_query_filter");
    function export_language_query_filter($query) {
    		global $wpdb;
    		//$query .= $wpdb->prepare(" WHERE ID IN (SELECT post_id FROM {$wpdb->wp_postmeta} WHERE meta_key = %s AND meta_value = %s) ", "_wpml2wpms_baseLanguage", "en");
    		//$query .= $wpdb->prepare(" INNER JOIN {$wpdb->wp_postmeta} ON ({$wpdb->posts}.ID = {$wpdb->wp_postmeta}.post_id) WHERE ($wpdb->wp_postmeta.meta_key} = %s AND ($wpdb->wp_postmeta.meta_value} = %s) ", "_wpml2wpms_baseLanguage", "en");
      		return $query;
    1. Neither of the commented out queries appear to work. At most they make it so that all of the results return rather than just a subset based on the selection on the export screen (ignoring post type radio button basically.
    2. Looking at /wp-admin/export.php and /wp-admin/includes/export.php it appears that the action export_wp is called before the full query is setup with innerjoin and where conditions such that nothing I would do within that action would have much chance of success.
    3. Found some examples of going an external route, but didn’t have success either.
    4. Did find that there is an active enhancement for the export API that added a bit of info to.

    If anyone has any examples of how to do this without doing an entire override of the export process that would be fantastic. Or if that is the only route, examples to show how much of the core code it should / could re-use. The plugin options screen already has a separate selection for post type and language.

  • The topic ‘Extending export to support custom field selection by plugin’ is closed to new replies.