private function wpv_get_other_parametric_filters($settings) { $ret = array(); $returned_post_types = isset($settings['post_type']) ? $settings['post_type'] : array(); $existing_real_parents = array_keys(wpv_recursive_post_hierarchy($returned_post_types, 4)); if (!empty($existing_real_parents)) { $ret['relationship'] = 'relationship'; } return $ret; }
/** * wpv_recursive_post_hierarchy * * Create a multidimensional array of Types post relationships * * @param $post_types (array) array of post type slugs to get the relationships from * @param $level (int) depth of recursion, we are hardcoding limiting it to 5 * * @return (array) * * @note this function is recursive * @note the returned array has the format * Array( * [father] => Array( * [grandpa-one] => Array( * [bisa] => Array() * ) * [grandma-one] => Array() * ) * [mother] => Array() * ) * * @since 1.6.0 */ function wpv_recursive_post_hierarchy( $post_types = array(), $level = 0 ) { $parents_array = array(); if ( ! is_array( $post_types ) ) { // Sometimes, when saving the Content Selection section with no post type selected, this is not an array // That can happen when switching to list taxonomy terms or users without selecting a post type first return $parents_array; } if ( function_exists( 'wpcf_pr_get_belongs' ) && $level < 5 ) { foreach ( $post_types as $post_type_slug ) { $this_parents = wpcf_pr_get_belongs( $post_type_slug ); if ( $this_parents != false && is_array( $this_parents ) ) { $new_parents = array_values( array_keys( $this_parents ) ); foreach ( $new_parents as $new_parent ) { $new_level = wpv_recursive_post_hierarchy( array( $new_parent ), $level + 1 ); $parents_array[$new_parent] = $new_level; } } } } return $parents_array; }