WP_Query modifications for Products pages

When GD Products Center plugin is active, it will attempt to detect and initialize itself for pages types related to products. When such page is detected, plugin will make modifications to main WordPress Query object and prepare for rendering output related to products.

You can use this in your own custom code written for GD Products Center. First thing you need to check to make sure that current query is related to GD Products Center is to use function is_gdpc(). If this returns true, you get access to the query element added to wp_query with more information about current products related page. To access it from global $wp_query object, new property is added to it called gdpc. Or you can get it using function gdpc_query().

This object contains several properties. It has two arrays for detected taxonomies and companies (in case of archive page)

  • taxonomies: key for taxonomy name, value for term for that taxonomy (terms are specified as slugs)
  • companies: key for company type name, value for company ID.

Than we have conditional values, all true or false.

  • is_single: has a function also – is_gdpc_single()
  • is_compare: has a function also – is_gdpc_compare()
  • is_archive: has a function also – is_gdpc_archive()
  • is_products: has a function also – is_gdpc_products()

And finally, there are few other values:

  • single_page: name of the page for the current single product
  • product_type: name of the current product type
  • current_page: number for current page if it has pages

When query is detected to be GD Products Center one, global $wp_query is also modified to set several conditionals to false: is_home, is_tax, is_tag, is_category, is_search.


Leave a Reply