[wp-trac] [WordPress Trac] #48180: extend export with filter for join and where clause

WordPress Trac noreply at wordpress.org
Mon Sep 30 10:29:31 UTC 2019


#48180: extend export with filter for join and where clause
-------------------------+-----------------------------
 Reporter:  mgleich      |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Export       |    Version:  5.2.3
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 In attachment I send a patch to add two lines for filters to change
 external the join and where clause to make it possible to export only the
 right posts.

 **I hope your can take it into the core.**

 Background: I have an user defined post type "bp-blog", which extends the
 default blog with buddypress group functionality. Therefor I save the
 buddy press group id in postmeta.

 Now I want export only the "bp-blog" posts for a specific group. Without
 the filter I cannot modify the request query and all "bp-blog" posts are
 exported.

 Here my usage of the the new filter:
 {{{#!php
 <?php
     add_filter('export_filter_join', 'export_filter_join', 0, 2);
     public function export_filter_join($join, $args = array()) {
         if ($args['content'] != 'bp-blog' && !isset($args['group'])) {
             return $join;
         }

         global $wpdb;

         $join .= " INNER JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID =
 {$wpdb->postmeta}.post_id)";

         return $join;
     }
 }}}

 and

 {{{#!php
 <?php
     add_filter('export_filter_where', 'export_filter_where', 0, 2);
     public function export_filter_where($where, $args = array()) {
         if ($args['content'] != 'bp-blog' && !isset($args['group'])) {
             return $where;
         }

         global $wpdb;

         $where .= " AND wp_postmeta.meta_key = '_bp_group' AND
 wp_postmeta.meta_value = {$args['group']}";

         return $where;
     }
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48180>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list