Skip to content

WooCommerce feature and Yoast "is multiple terms query" logic conflict #911

Description

@kallehauge

Have you searched for similar issues before submitting this one? Yes

Is this a bug, question or feature request? Feature request, I guess

Describe the issue you encountered:

There is a logic conflict when the WooCommerce feature is enabled with Yoast. The conflict will cause issues like "all product category archives will be converted to robots => noindex" due to a conflict with Yoasts WPSEO_Frontend::is_multiple_terms_query logic that then states that the page is not a single term archive and should therefor not be indexed by robots.

Example: If we have a parent category called Clothes with a child category named Hoodies, then the parent (Clothes) will be shown as noindex but the child category (Hoodies) will not.

TL;DR Parent term archives with child terms is being set to robots noindex by Yoast.

Current WordPress version: 4.8.1

Current ElasticPress version: Develop branch

Current Elasticsearch version: 2.3

Where do you host your Elasticsearch server: AWS

Other plugins installed (WooCommerce, Simple Redirect Manager, etc..):

  • WooCommerce
  • Yoast

Steps to reproduce:

  1. Install and enable WordPress + WooCommerce + Yoast + ElasticPress.
  2. Enable EP's WooCommerce feature.
  3. Go to a product category with child terms and inspect the DOM. The parent's term archive is now changed from robots => indexed to robots => noindex.

Why this happens:

This happens because WPSEO_Frontend::is_multiple_terms_query assumes an internal WP Tax Query logic to "include_children" but the way we support shorthand taxonomy queries, we fetch all child terms and converting them into a WP_Tax_Query instead:

ep_wc_translate_args() in woocommerce.php:

/**
 * Next check if any taxonomies are in the root of query vars (shorthand form)
 */
foreach ( $supported_taxonomies as $taxonomy ) {
	$term = $query->get( $taxonomy, false );

	if ( ! empty( $term ) ) {
		$integrate = true;

		$terms = array( $term );

		// to add child terms to the tax query
		if ( is_taxonomy_hierarchical( $taxonomy ) ) {
			$term_object = get_term_by( 'slug', $term, $taxonomy );
			$children    = get_term_children( $term_object->term_id, $taxonomy );
			if ( $children ) {
				foreach ( $children as $child ) {
					$child_object = get_term( $child, $taxonomy );
					$terms[]      = $child_object->slug;
				}
			}

		}

		$tax_query[] = array(
			'taxonomy' => $taxonomy,
			'field'    => 'slug',
			'terms'    => $terms,
		);
	}
}

Simplified WPSEO_Frontend::is_multiple_terms_query:

protected function is_multiple_terms_query() {
	global $wp_query;

	$term = get_queried_object();
	$queried_terms = $wp_query->tax_query->queried_terms;
	return count( $queried_terms[ $term->taxonomy ]['terms'] ) > 1;
}

Solution?

A solution could be to remove our Tax_query after we have fetched posts in EP_WP_Query_Integration::filter_the_posts if we add an action hook?

The reason I think that this is something we could/should solve in this plugin is that I feel like it should be as seamless as possible to use it without changing the logic more than necessary. So a process of "Clean up after ourselves" after we make changes seems logical to me. We should, at the very least, find a solution to be able to fit right in with Yoast as one of the most used plugins.

Experimental code that I currently use to support Yoast: Pull-Request. This is not ment to be a finial solution but it currently works for me.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions