I have a Teams-to-Members relationship (One-to-Many ) .
On the individual Member account page there is a form where the Member can update which Team they belong too. Currently, there is a dropdown of all the Teams, and they select which team they would like to switch their Membership to.
However, not all Teams are currently accepting new Members. Teams that have indicated they will take on new Members have marked the custom Taxonomy "Actives" as "Active". I would like to have only the Teams with the correct taxonomy ("active") displayed and able to be selected in the dropdown list.
Hello. Thank you for contacting the Toolset support.
I would like to know first are you using post-relationship form or post edit form to update the post-relationship between member and team?
Can you please share problem URL of the member account page where I can see the form as well as admin access details and let me see what we can do here.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
It is a Post Edit form for the post type "Member". The form works great to update the member's team affiliation. The post type Member is connected (via authorship) to the user account, and post type "Member" already exists at the time the user goes to make this edit. The only issue is that I would like to only show Teams with tag "active" in the dropdown list, instead of all the teams we have ever had. I'm assuming I should put something in there that filters the taxonomy.
It is not that I have tried to filter the dropdown list by taxonomy and it hasn't worked... I don't know how to do this at all so haven't even tried. If there is not a simple answer for this I will duplicate the post types and forms on a dev site and you can take a look.
There is no native feature to filter the parent post dropdown with the specific taxonomy term.
However, here is the code snippet that should work for you as a workaround.
- hidden link
You can adjust the values of post type and even make sure that the snippet should run at your desired post/post type only. If you do not know how to do it, you are welcome to share the test site access details and I'm happy to set it up for you.
Thanks for your reply. I tried to use the snippet provided, but clearly I am doing something wrong. I would love your help, please facilitate me getting the admin login info to you.
Please share problem URL where you added the form and with what field you want to filter it with what term?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I've added the following filter code to "Custom Code" section offered by Toolset:
=> hidden link
function filter_parent_post_select2_by__taxonomy_term( $query ){
global $post;
if($_REQUEST['cred_post_id'] == 324) { // post id where you added the form
if (defined('DOING_AJAX') && DOING_AJAX) {
//check for the action & slug to focus in on a specific dropdown if you have multiple dropdown in the form
if($_REQUEST['action']=='select2_potential_relationship_parents'){
if($query->query['post_type'][0]=='team'){
$taxquery = array( array(
'taxonomy' => 'active',
'field' => 'slug',
'terms' => array('active'),
'operator'=> 'IN' ));
$query->set( 'tax_query', $taxquery );
}
}
}
}
}
add_action( 'pre_get_posts', 'filter_parent_post_select2_by__taxonomy_term', 101, 1 );
I can see its filtering the parent post dropdown with taxonomy term active correctly. Can you please confirm it works at your end as well.
Thank you, yes, it works, but only on that one individual Member - not on each and every Member Post.
if($_REQUEST['cred_post_id'] == 324)
324 is the post ID of one particular Member. But all members need to be able to update their Team the same way. The form is on the Single Post Template for the Custom Post Type "Member".
The number of the Member Single Post Template is 333. I tried this to see if it would work then on all members, but it did not.
The number of the Cred Form itself is 337. I tried this as well, but it did not work either.
Ok. I understand that you want to add the form on all single post of post type "member":
I've adjusted the code as given under:
function filter_parent_post_select2_by__taxonomy_term( $query ){
global $post;
$mypost = get_post($_REQUEST['cred_post_id']);
if($mypost->post_type == 'member') { // post id where you added the form
if (defined('DOING_AJAX') && DOING_AJAX) {
//check for the action & slug to focus in on a specific dropdown if you have multiple dropdown in the form
if($_REQUEST['action']=='select2_potential_relationship_parents'){
if($query->query['post_type'][0]=='team'){
$taxquery = array( array(
'taxonomy' => 'active',
'field' => 'slug',
'terms' => array('active'),
'operator'=> 'IN' ));
$query->set( 'tax_query', $taxquery );
}
}
}
}
}
add_action( 'pre_get_posts', 'filter_parent_post_select2_by__taxonomy_term', 101, 1 );
Can you please confirm it works as expected on single posts of post type "member".