Override custom taxonomies

Change which post types use affiliate-toolkit taxonomies and how they are registered, with the filters atkp_taxonomy_posttypes and atkp_register_taxonomy.

affiliate-toolkit registers taxonomies for your products: the product category plus every custom taxonomy you create in the Custom Fields settings or as a field of type "Taxonomy" in a field group. Two filters let you change how these taxonomies are registered, for example to use the product category on normal posts as well or to expose a taxonomy in the REST API.

Put the code in the functions.php of your child theme or in a small site-specific plugin. Both filters run while the product post type is registered on init.

Change the post types of a taxonomy

The filter atkp_taxonomy_posttypes runs once per taxonomy and decides which post types it is attached to. By default that is only atkp_product. The Custom Fields module adds atkp_fieldgroup to the product category (so field groups can be assigned to it), and the Import Sets module adds atkp_importset.

/**
 * Also assign the product category to normal posts.
 *
 * @param array           $post_types Post types the taxonomy is registered for.
 * @param atkp_udtaxonomy $taxonomy   The taxonomy definition (object, not a string).
 */
function my_atkp_taxonomy_posttypes( $post_types, $taxonomy ) {
    if ( $taxonomy->isproductcategory ) {
        $post_types[] = 'post';
    }

    return $post_types;
}
add_filter( 'atkp_taxonomy_posttypes', 'my_atkp_taxonomy_posttypes', 10, 2 );
ParameterTypeDescription
$post_typesarrayPost types the taxonomy is registered for. Default: array( 'atkp_product' ), extended by active modules.
$taxonomyobject (atkp_udtaxonomy)The taxonomy definition. Useful properties: name, caption, captionplural, isproductcategory, isproductgroup, issystemfield, isnewtax (created in a field group).
Return valuearrayThe modified list of post types.

The second parameter is an object, not the taxonomy name. Compare $taxonomy->name or use a flag such as $taxonomy->isproductcategory. Older examples that compare the parameter with a string never match.

Change the registration arguments

The filter atkp_register_taxonomy runs directly before register_taxonomy() and receives the complete argument array.

/**
 * Make the custom taxonomy "brand" available in the block editor and REST API.
 *
 * @param array  $taxargs       Arguments for register_taxonomy().
 * @param string $taxonomy_name Name of the taxonomy, e.g. "brand".
 */
function my_atkp_register_taxonomy( $taxargs, $taxonomy_name ) {
    if ( 'brand' === $taxonomy_name ) {
        $taxargs['show_in_rest'] = true;
    }

    return $taxargs;
}
add_filter( 'atkp_register_taxonomy', 'my_atkp_register_taxonomy', 20, 2 );
ParameterTypeDescription
$taxargsarrayArguments for register_taxonomy().
$taxonomy_namestringName (slug) of the taxonomy, for example brand.
Return valuearrayThe modified arguments.

Defaults set by the plugin:

ArgumentDefault
hierarchicaltrue
publicfalse (the Frontend Product Pages module sets it to true with priority 10)
show_uitrue
show_in_menufalse (the terms are managed from the affiliate-toolkit menu)
show_admin_columntrue for the product category, otherwise false
query_vartrue
capabilitiesmanage, edit, delete and assign terms all require edit_posts

Notes

  • The name of the product category taxonomy depends on the site language when the plugin was set up: productcategory on English sites, produktkategorie on German sites. Checking $taxonomy->isproductcategory avoids that problem.
  • A taxonomy whose name already exists (registered by another plugin or the theme) is skipped by affiliate-toolkit, and the filters are not called for it.
  • Renaming a taxonomy afterwards is not supported. After changing taxonomies, save the permalinks once (Settings → Permalinks → Save Changes).