Ticket #16149: 16149.diff
| File 16149.diff, 2.7 KB (added by nacin, 2 years ago) |
|---|
-
wp-includes/post.php
534 534 $format = 'post-format-' . $format; 535 535 } 536 536 537 if ( ! term_exists( 'post-format-standard', 'post_format' ) ) 538 wp_insert_term( 'post-format-standard', 'post_format' ); 539 537 540 return wp_set_post_terms($post->ID, $format, 'post_format'); 538 541 } 539 542 … … 5144 5147 } 5145 5148 5146 5149 /** 5147 * Filters the request to allow for the format prefix .5150 * Filters the request to allow for the format prefix and handles the standard post format query. 5148 5151 * 5149 5152 * @access private 5150 5153 * @since 3.1.0 … … 5152 5155 function _post_format_request( $qvs ) { 5153 5156 if ( ! isset( $qvs['post_format'] ) ) 5154 5157 return $qvs; 5155 $slugs = array_flip( get_post_format_slugs() ); 5156 if ( isset( $slugs[ $qvs['post_format'] ] ) ) 5157 $qvs['post_format'] = 'post-format-' . $slugs[ $qvs['post_format'] ]; 5158 $by_raw_slug = get_post_format_slugs(); 5159 $by_translated_slug = array_flip( $by_raw_slug ); 5160 if ( isset( $by_translated_slug[ $qvs['post_format'] ] ) ) { 5161 if ( 'standard' == $by_translated_slug[ $qvs['post_format'] ] ) { 5162 // If 'standard', then query every persistent format with a NOT IN instead. 5163 unset( $qvs['post_format'] ); 5164 $formats = array(); 5165 $raw_slugs = array_diff( array_keys( $by_raw_slug ), array( 'standard' ) ); 5166 foreach ( $raw_slugs as $format ) { 5167 $formats[] = 'post-format-' . $format; 5168 } 5169 if ( ! isset( $qvs['tax_query'] ) ) 5170 $qvs['tax_query'] = array(); 5171 $qvs['tax_query'][] = array( 'taxonomy' => 'post_format', 'terms' => $formats, 'field' => 'slug', 'operator' => 'NOT IN' ); 5172 $qvs['tax_query']['relation'] = 'AND'; 5173 // Repair the query flags and queried object. 5174 add_action( 'parse_query', '_post_format_parse_query' ); 5175 } else { 5176 $qvs['post_format'] = 'post-format-' . $by_translated_slug[ $qvs['post_format'] ]; 5177 } 5178 } 5179 // Only post types that support formats should be queried. 5180 // Especially important for the NOT IN 'standard' format query. 5181 $tax = get_taxonomy( 'post_format' ); 5182 $qvs['post_type'] = $tax->object_type; 5158 5183 return $qvs; 5159 5184 } 5160 5185 add_filter( 'request', '_post_format_request' ); 5161 5186 5162 5187 /** 5188 * Filters the query object when the standard post format is requested. 5189 * 5190 * @access private 5191 * @since 3.1.0 5192 */ 5193 function _post_format_parse_query( $query ) { 5194 $query->is_tax = $query->is_archive = true; 5195 $query->is_home = false; 5196 $query->queried_object = get_term_by( 'slug', 'post-format-standard', 'post_format' ); 5197 $query->queried_object_id = $query->queried_object->term_id; 5198 } 5199 5200 /** 5163 5201 * Filters the post format term link to remove the format prefix. 5164 5202 * 5165 5203 * @access private