When viewing a Parent term in a hierarchical taxonomy, display objects contained within children too. Props scribu. Fixes #12533

git-svn-id: http://svn.automattic.com/wordpress/trunk@13787 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
dd32 2010-03-21 02:52:00 +00:00
parent 68445ab030
commit e2a7385be8

View File

@ -94,7 +94,7 @@ function wp_reset_query() {
* *
* @return bool True if page is archive. * @return bool True if page is archive.
*/ */
function is_archive () { function is_archive() {
global $wp_query; global $wp_query;
return $wp_query->is_archive; return $wp_query->is_archive;
@ -108,7 +108,7 @@ function is_archive () {
* *
* @return bool True if page is attachment. * @return bool True if page is attachment.
*/ */
function is_attachment () { function is_attachment() {
global $wp_query; global $wp_query;
return $wp_query->is_attachment; return $wp_query->is_attachment;
@ -268,7 +268,7 @@ function is_tax( $taxonomy = '', $term = '' ) {
* *
* @return bool * @return bool
*/ */
function is_comments_popup () { function is_comments_popup() {
global $wp_query; global $wp_query;
return $wp_query->is_comments_popup; return $wp_query->is_comments_popup;
@ -282,7 +282,7 @@ function is_comments_popup () {
* *
* @return bool * @return bool
*/ */
function is_date () { function is_date() {
global $wp_query; global $wp_query;
return $wp_query->is_date; return $wp_query->is_date;
@ -296,7 +296,7 @@ function is_date () {
* *
* @return bool * @return bool
*/ */
function is_day () { function is_day() {
global $wp_query; global $wp_query;
return $wp_query->is_day; return $wp_query->is_day;
@ -310,7 +310,7 @@ function is_day () {
* *
* @return bool * @return bool
*/ */
function is_feed () { function is_feed() {
global $wp_query; global $wp_query;
return $wp_query->is_feed; return $wp_query->is_feed;
@ -324,7 +324,7 @@ function is_feed () {
* *
* @return bool * @return bool
*/ */
function is_comment_feed () { function is_comment_feed() {
global $wp_query; global $wp_query;
return $wp_query->is_comment_feed; return $wp_query->is_comment_feed;
@ -339,7 +339,7 @@ function is_comment_feed () {
* *
* @return bool True, if front of site. * @return bool True, if front of site.
*/ */
function is_front_page () { function is_front_page() {
// most likely case // most likely case
if ( 'posts' == get_option('show_on_front') && is_home() ) if ( 'posts' == get_option('show_on_front') && is_home() )
return true; return true;
@ -361,7 +361,7 @@ function is_front_page () {
* *
* @return bool True if blog view homepage. * @return bool True if blog view homepage.
*/ */
function is_home () { function is_home() {
global $wp_query; global $wp_query;
return $wp_query->is_home; return $wp_query->is_home;
@ -375,7 +375,7 @@ function is_home () {
* *
* @return bool * @return bool
*/ */
function is_month () { function is_month() {
global $wp_query; global $wp_query;
return $wp_query->is_month; return $wp_query->is_month;
@ -429,7 +429,7 @@ function is_page ($page = '') {
* *
* @return bool * @return bool
*/ */
function is_paged () { function is_paged() {
global $wp_query; global $wp_query;
return $wp_query->is_paged; return $wp_query->is_paged;
@ -491,7 +491,7 @@ function is_robots() {
* *
* @return bool * @return bool
*/ */
function is_search () { function is_search() {
global $wp_query; global $wp_query;
return $wp_query->is_search; return $wp_query->is_search;
@ -512,7 +512,7 @@ function is_search () {
* @param mixed $post Either post or list of posts to test against. * @param mixed $post Either post or list of posts to test against.
* @return bool * @return bool
*/ */
function is_single ($post = '') { function is_single($post = '') {
global $wp_query; global $wp_query;
if ( !$wp_query->is_single ) if ( !$wp_query->is_single )
@ -557,7 +557,7 @@ function is_singular() {
* *
* @return bool * @return bool
*/ */
function is_time () { function is_time() {
global $wp_query; global $wp_query;
return $wp_query->is_time; return $wp_query->is_time;
@ -571,7 +571,7 @@ function is_time () {
* *
* @return bool * @return bool
*/ */
function is_trackback () { function is_trackback() {
global $wp_query; global $wp_query;
return $wp_query->is_trackback; return $wp_query->is_trackback;
@ -585,7 +585,7 @@ function is_trackback () {
* *
* @return bool * @return bool
*/ */
function is_year () { function is_year() {
global $wp_query; global $wp_query;
return $wp_query->is_year; return $wp_query->is_year;
@ -599,7 +599,7 @@ function is_year () {
* *
* @return bool True, if nothing is found matching WordPress Query. * @return bool True, if nothing is found matching WordPress Query.
*/ */
function is_404 () { function is_404() {
global $wp_query; global $wp_query;
return $wp_query->is_404; return $wp_query->is_404;
@ -1134,7 +1134,7 @@ class WP_Query {
* @since 1.5.0 * @since 1.5.0
* @access public * @access public
*/ */
function init () { function init() {
unset($this->posts); unset($this->posts);
unset($this->query); unset($this->query);
$this->query_vars = array(); $this->query_vars = array();
@ -1227,7 +1227,7 @@ class WP_Query {
* *
* @param string|array $query * @param string|array $query
*/ */
function parse_query ($query) { function parse_query($query) {
if ( !empty($query) || !isset($this->query) ) { if ( !empty($query) || !isset($this->query) ) {
$this->init(); $this->init();
if ( is_array($query) ) if ( is_array($query) )
@ -1996,23 +1996,29 @@ class WP_Query {
if ( '' != $q['taxonomy'] ) { if ( '' != $q['taxonomy'] ) {
$taxonomy = $q['taxonomy']; $taxonomy = $q['taxonomy'];
$tt[$taxonomy] = $q['term']; $tt[$taxonomy] = $q['term'];
$terms = get_terms($q['taxonomy'], array('slug'=>$q['term']));
} else { } else {
foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) { foreach ( $GLOBALS['wp_taxonomies'] as $taxonomy => $t ) {
if ( $t->query_var && '' != $q[$t->query_var] ) { if ( $t->query_var && '' != $q[$t->query_var] ) {
$terms = get_terms($taxonomy, array('slug'=>$q[$t->query_var])); $tt[$taxonomy] = $q[$t->query_var];
if ( !is_wp_error($terms) ) break;
break;
} }
} }
} }
$terms = get_terms($taxonomy, array('slug' => $tt[$taxonomy], 'hide_empty' => !is_taxonomy_hierarchical($taxonomy)));
if ( is_wp_error($terms) || empty($terms) ) { if ( is_wp_error($terms) || empty($terms) ) {
$whichcat = " AND 0 "; $whichcat = " AND 0 ";
} else { } else {
foreach ( $terms as $term ) foreach ( $terms as $term ) {
$term_ids[] = $term->term_id; $term_ids[] = $term->term_id;
if ( is_taxonomy_hierarchical($taxonomy) ) {
$children = get_term_children($term->term_id, $taxonomy);
$term_ids = array_merge($term_ids, $children);
}
}
$post_ids = get_objects_in_term($term_ids, $taxonomy); $post_ids = get_objects_in_term($term_ids, $taxonomy);
if ( !is_wp_error($post_ids) && count($post_ids) ) { if ( !is_wp_error($post_ids) && !empty($post_ids) ) {
$whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") "; $whichcat .= " AND $wpdb->posts.ID IN (" . implode(', ', $post_ids) . ") ";
$post_type = 'any'; $post_type = 'any';
$q['post_status'] = 'publish'; $q['post_status'] = 'publish';
@ -2734,7 +2740,7 @@ class WP_Query {
* @param string $query URL query string. * @param string $query URL query string.
* @return WP_Query * @return WP_Query
*/ */
function WP_Query ($query = '') { function WP_Query($query = '') {
if (! empty($query)) { if (! empty($query)) {
$this->query($query); $this->query($query);
} }
@ -2752,7 +2758,7 @@ class WP_Query {
* *
* @return null If no link is found, null is returned. * @return null If no link is found, null is returned.
*/ */
function wp_old_slug_redirect () { function wp_old_slug_redirect() {
global $wp_query; global $wp_query;
if ( is_404() && '' != $wp_query->query_vars['name'] ) : if ( is_404() && '' != $wp_query->query_vars['name'] ) :
global $wpdb; global $wpdb;
@ -2826,5 +2832,4 @@ function setup_postdata($post) {
return true; return true;
} }
?>
?>