Filter
uncanny-automator
automator_allowed_category_taxonomy_children_post_types
Filters allowed post types for category taxonomy children when checking for child relationships.
add_filter( 'automator_allowed_category_taxonomy_children_post_types', $callback, 10, 1 );
Description
Filters the post types allowed to have hierarchical term relationships checked within Uncanny Automator. Developers can modify this array to include or exclude specific post types when determining if a term is a child of another for recipe triggers and actions. Defaults to 'post'.
Usage
add_filter( 'automator_allowed_category_taxonomy_children_post_types', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Allow 'automator_allowed_category_taxonomy_children_post_types' filter to include 'page' post type
* in addition to the default 'post' type. This allows Automator to check for child terms
* in taxonomies associated with pages, not just posts.
*
* @param array $allowed_post_types An array of post types that can have their taxonomy children checked.
* @return array Modified array of allowed post types.
*/
add_filter( 'automator_allowed_category_taxonomy_children_post_types', function( $allowed_post_types ) {
// Add 'page' to the list of allowed post types.
$allowed_post_types[] = 'page';
// Ensure uniqueness in case it was already added.
$allowed_post_types = array_unique( $allowed_post_types );
return $allowed_post_types;
}, 10, 1 );
?>
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/wp/helpers/wp-helpers.php:888
uncanny-automator-pro/src/integrations/wp/helpers/wp-pro-helpers.php:993
public function get_term_child_of( $post_terms, $parent_term_id, $taxonomy, $post_id ) {
if ( empty( $post_terms ) || ! is_array( $post_terms ) ) {
return false;
}
// Check Post Type for the post
$allowed_post_types = apply_filters( 'automator_allowed_category_taxonomy_children_post_types', array( 'post' ) );
if ( ! in_array( get_post_type( $post_id ), $allowed_post_types, true ) ) {
return false;
}
$allowed_taxonomies = apply_filters( 'automator_allowed_category_taxonomy_children_taxonomies', array( 'category' ) );
if ( ! is_array( $allowed_taxonomies ) || ! in_array( $taxonomy, $allowed_taxonomies, true ) ) {
return false;
}
// Get all child terms of the parent term
$child_terms = get_term_children( $parent_term_id, $taxonomy );
if ( empty( $child_terms ) || is_wp_error( $child_terms ) ) {
return false;
}
foreach ( $post_terms as $post_term ) {
if ( in_array( $post_term->term_id, $child_terms, true ) && $post_term->taxonomy === $taxonomy ) {
return $post_term;
}
}
return false;
}