Tell us what you are trying to do?
I have a hierarchical taxonomy of Locations with the hierarchy being Continent > Region > Country. The hierarchy is useful for frontend search, however when submitting a new post using a CRED form I want the user to only be able to select "Country" level terms, not the regions or continents.
Is there any documentation that you are following?
I have implemented the code from this forum post: https://toolset.com/forums/topic/how-to-display-only-certain-taxonomy-terms-on-cred-form/
It works as advertised, and I only see the terms that are selected. However (as also mentioned in the forum thread) in order for a term to be visible all parents and grand parents must be visible, which defeat my purpose.
Is there a similar example that we can see?
Here is my actual code:
// Alter the query to only get the terms where the custom field use-in-form checked.
function wp_custom_get_terms_args( $args, $taxonomies ) {
error_log('wp_custom_get_terms_args');
$args['meta_query'] = array(
array(
'key' => 'wpcf-selectable',
'value' => '1',
'compare' => '='
),
);
return $args;
}
// Add the query filter for our form.
add_action('toolset_forms_frontend_flow_form_start', function($form_object, $form_attributes){
$forms = array(8124);
if ( in_array( $form_object->ID, $forms ) ) {
add_filter( 'get_terms_args', 'wp_custom_get_terms_args', 10, 2 );
}
}, 10, 2);
// remove the query filter for the other parts of the website
add_action('toolset_forms_frontend_flow_form_end', function(){
remove_filter( 'get_terms_args', 'wp_custom_get_terms_args');
}, 10, 2);
I wonder if there is another method I could use to achieve the same goal of filtering the Select Options?