A more reliable get_queried_object() in WooCommerce 11.0

Starting from WooCommerce 11.0, using get_queried_object() in the Shop page will be consistent with the other pages and will return the WP_Post object of the Shop page.

Until now, calling get_queried_object() in the Shop page returned the WP_Post_Type object for products. That was a misalignment between WooCommerce and WordPress that had caused some confusion in the past. Starting from WooCommerce 11.0, this will be fixed and get_queried_object() will return the WP_Post relative to the Shop page, including when it’s set as the front page. This way, get_queried_object() works in the Shop page as it does in similar screens like the Posts page in WordPress Reading settings.

How can developers tell if they are affected?

Your extension or custom code might be affected if it calls or reads get_queried_object(), get_queried_object_id(), $query->queried_object, or $query->queried_object_id in the Shop page and expects the WP_Post_Type object for products instead of the WP_Post object for the Shop page.

Before:

// Shop page - the only exception
get_queried_object(); // -> WP_Post_Type
get_post_type_object( 'product' ); // -> WP_Post_Type

// Other pages
get_queried_object(); // -> WP_Post
get_post_type_object( 'product' ); // -> WP_Post_Type

After:

// All pages unified - including Shop page
get_queried_object(); // -> WP_Post
get_post_type_object( 'product' ); // -> WP_Post_Type

This change does not affect:

  • single product pages: the queried object continues to be the WP_Post object for the product
  • product taxonomies including categories, tags, brand, or attributes: the queried object continues to be the WP_Term object for the product term
  • other post type archives or singular pages

Conditional functions like is_shop(), is_archive(), or is_post_type_archive( 'product' ) remain unchanged and continue to work as they used to.

What action do developers need to take if affected?

If your extension reads the queried object on the Shop page, check the object type before accessing type-specific properties.

If you need to access the WP_Post_Type object for products, the recommended approach is to use get_post_type_object():

$product_post_type = get_post_type_object( 'product' );

if ( $product_post_type instanceof WP_Post_Type ) {
  // The products WP_Post_Type object can still be
  // accessed via `get_post_type_object()`.
}

Related PR:


Leave a Reply

Your email address will not be published. Required fields are marked *