WP 4.4-alpha: taxonomy.php makes little babies ;-)

The taxonomy is the basis of categories, keywords (tags) and other rankings in WordPress (like language with xili-language trilogy). Since WP 2.3, all key components are found in the file wp-includes / taxonomy.php. WP 4.4 release announces a big change. The developer will seek information in 3 files:

<?php
/**
 * Core Taxonomy API
 *
 * @package WordPress
 * @subpackage Taxonomy
 * @since 2.3.0
 */

/** Core taxonomy functionality */
require_once( ABSPATH . WPINC . '/taxonomy-functions.php' );

/** WP_Term class */
require_once( ABSPATH . WPINC . '/class-wp-term.php' );

/** WP_Tax_Query class */
require_once( ABSPATH . WPINC . '/class-wp-tax-query.php' );

including the new wp-term class that strengthens the previous object describing the terms methodically …

Added to this is the new term meta table that will be very useful to supplement the description of a tag, for example.

It is too early to draw conclusions but Xili-language will continue to take advantage of these new classes, functions and tables.

For now, Xili-language still works;-)

Justin Tadlock has published a comprehensive article for developers.

To still follow (closely) …

Multisite and custom taxonomy… quid ?

In multisite context and WordPress version 4.2.2, with this function in blog_id #3:

switch_to_blog( 2 );

have we really switched in blog_id #2 to fire a query (new WP_Query ( $query ) ;) including a custom taxonomy here (‘domain’) ?

// extract of the query
'tax_query'   => array(
'relation' => 'AND',
	array(
	'field'    => 'term_id',
		'taxonomy' => 'category',
		'terms'    => array ('publication', 'evenement'),
		'operator' => 'IN'
	),
array(
	'field'    => 'slug',
	'taxonomy' => 'domain',
	'terms'    =>  array( 'aerien', 'sous-marin'),
	'operator' => 'IN'
	)
)

In fact NO, because interpreting $query needs the taxonomy to be declared in blog_id #3 where this code is.
A workaround ?
The plugin registering this new taxonomy must not be ‘network activated’ but one by one in #2 and #3 and in properties of this taxonomy, define where the taxonomy must be visible (here #2)
'show_ui' => ($current_blog->blog_id == 2 ) ? true :false,

With this workaround, the deficiency of switch_to_blog( 2 ); is “fixed” and it now possible to display with a custom function (including complex query) in theme of website #3 a list of posts coming from #2.

How to include language in a query with xili-language ?

$faq_args = array(
        'post_type'      => 'hrf_faq',
        'post_status'    => 'publish',
        'posts_per_page' => -1,
        'orderby'        => 'menu_order',
        'order'          => 'ASC',
        'lang' => xili_curlang()
   );

   if( $faq_params['category'] != '' ){
      $faq_args['category_name'] = $faq_params['category'];
   }

   $faq_query = new WP_Query( $faq_args );

   if( $faq_query->have_posts() ):
      while( $faq_query->have_posts() ):
         $faq_query->the_post();

In the lines above, the WP_Query is called with query vars as in URI. Currently, the result is good because the request will be now transformed in an array of params (and taxonomy).

TIPS: But it is possible to give a better description with arrays passed as below (remember ‘language’ is a taxonomy since 6 years):

 if ( $faq_params['lang'] ) {
	   		$lang_slug = ( $faq_params['lang'] == 'cur') ? xili_curlang() : $faq_params['lang'] ;

	   		$query = array(
				'numberposts' => -1,
				'post_type' => 'hrf_faq',
				'tax_query' => array(
					'relation' => 'AND',

					array(
						'field'    => 'slug',
						'taxonomy' => 'language',
						'terms'    => $lang_slug,
					),
				),
			);
			if ($faq_params['category'] != '') {
				$query['tax_query'][] = array(
						'field'    => 'slug',
						'taxonomy' => 'category',
						'terms'    => explode (',', $faq_params['category'])
					);

			}

		} else {
			$query = array(
				'numberposts' => -1,
				'post_type' => 'hrf_faq'
				);

			if ($faq_params['category'] != '') {
				$query['tax_query'] = array(
					array(
						'field'    => 'slug',
						'taxonomy' => 'category',
						'terms'    => explode (',', $faq_params['category'])
					));

			}

		}

		$faqs = new WP_Query( $query ) ;
		if ($faqs) {
			while ( $faqs->have_posts() ) : $faqs->the_post();

				$ID = get_the_ID();

For more accurate query, it will be easier to introduce others parameters (taxonomy, custom fields (meta), sorting…)..

Reference in codex.