WordPress.org

Make WordPress Core

Ticket #4082: 4802.patch

File 4802.patch, 3.1 KB (added by tacker, 8 years ago)
  • wp-admin/export.php

     
    2525<select name="author"> 
    2626<option value="all" selected="selected"><?php _e('All'); ?></option> 
    2727<?php 
    28 $authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" );   
     28$authors = $wpdb->get_col( "SELECT post_author FROM $wpdb->posts GROUP BY post_author" ); 
    2929foreach ( $authors as $id ) { 
    3030        $o = get_userdata( $id ); 
    3131        echo "<option value='$o->ID'>$o->display_name</option>"; 
     
    3535</td> 
    3636</tr> 
    3737</table> 
     38<table> 
     39<tr> 
     40<th><?php _e('Restrict Category:'); ?></th> 
     41<td> 
     42<select name="category"> 
     43<option value="all" selected="selected"><?php _e('All'); ?></option> 
     44<?php 
     45 
     46$categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories ORDER BY cat_name"); 
     47 
     48foreach ( $categories as $category ) { 
     49    echo "<option value='$category->cat_ID'>$category->cat_name</option>"; 
     50} 
     51 
     52?> 
     53</select> 
     54</td> 
     55</tr> 
     56</table> 
    3857<p class="submit"><input type="submit" name="submit" value="<?php _e('Download Export File'); ?> &raquo;" /> 
    3958<input type="hidden" name="download" value="true" /> 
    4059</p> 
     
    5675$where = ''; 
    5776if ( isset( $_GET['author'] ) && $_GET['author'] != 'all' ) { 
    5877        $author_id = (int) $_GET['author']; 
    59         $where = " WHERE post_author = '$author_id' "; 
     78        $where = " WHERE p.post_author = '$author_id' "; 
     79} 
     80$category_id = false; 
     81if ( isset( $_GET['category'] ) && $_GET['category'] != 'all' ) { 
     82    $category_id = (int) $_GET['category']; 
     83    $where .= (empty($where) ? ' WHERE ' : ' AND ') . ' c.post_id = p.id AND c.category_id = ' . $category_id; 
    6084} 
    6185 
    62 $posts = $wpdb->get_results("SELECT * FROM $wpdb->posts $where ORDER BY post_date_gmt ASC"); 
     86if ($category_id) { 
     87    $posts = $wpdb->get_results("SELECT p.* FROM $wpdb->posts p, $wpdb->post2cat c $where ORDER BY post_date_gmt ASC"); 
     88} else { 
     89    $posts = $wpdb->get_results("SELECT p.* FROM $wpdb->posts p $where ORDER BY post_date_gmt ASC"); 
     90} 
    6391 
    64 $categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts ON (post_id <=> id) $where GROUP BY cat_id"); 
     92if ($category_id) { 
     93    $categories = (array) $wpdb->get_results('SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM ' .  $wpdb->categories . ' WHERE cat_ID = ' . $category_id); 
     94} else { 
     95    $categories = (array) $wpdb->get_results("SELECT cat_ID, cat_name, category_nicename, category_description, category_parent, posts_private, links_private FROM $wpdb->categories LEFT JOIN $wpdb->post2cat ON (category_id = cat_id) LEFT JOIN $wpdb->posts p ON (post_id <=> id) $where GROUP BY cat_id"); 
     96} 
    6597 
    6698function wxr_missing_parents($categories) { 
    6799        if ( !is_array($categories) || empty($categories) )