Ok, I undertand. Then, I need to do this filter and I see an alternative solution but I don't know how to do it.
The solution is: when user save a post "Acció formativa", copying (by hook?) the taxonomy "Temàtiques dels cursos" from the referenced "Curs" to a new field in "Acció formativa".
Then I'll be able to filter with this new field in "Acció formativa".
If I understand correctly, when the user saves the post you want the taxonomy of the post that was saved in the post reference field to be copied to the post that is being created correct?
If that is the case then this can work given that the taxonomy is also assigned to the post being created. If you're familiar with php then you can use the hook below to do this when the post is being created on the backend. https://developer.wordpress.org/reference/hooks/save_post/
Please let me know if my interpretation is correct.
Thanks,
Shane
I've got dificulties to get and put the taxonomy (is Hierarchical). Please, can you help me ?
My code is:
function func_save_custom_field_value( $post_id, $post, $update ) {
$parent = toolset_get_related_post($post_id,'curs-de-referencia');//that works fine
//Here are the problem
//get the taxonomy with slug=tematica-de-curs (is Hierarchical) list of terms from the parent
$post_categories = get_the_terms( $parent, 'tematica-de-curs' );
//put the taxonomy list of terms in the post
wp_set_post_terms($post_id, $post_categories);
Hi Shane,
the problem is this two spteps,This code doesn't works:
1) get the parent categories (slug category is 'tematica-de-curs') :
$post_categories = get_the_terms( $parent, 'tematica-de-curs' );
2) put this categories to the post user is editing:
wp_set_post_terms($post_id, $post_categories);
The two CPT uses the same taxonomy 'tematica-de-curs'.
Basically, I don't know how to get and put the categories.
** HOW can I do that You said?: Can you perform a var_dump() function on the $post_categories variable so that I can see what is being stored in this variable?
I ran through your code again and found that you're using the relationship slug "curs-de-referencia" in the toolset_get_related_post() function.
However checking on your website i found that there are no relationships with that relationship slug. We may need to slow down a bit and Identify the 2 post types that we are working with and which post type you want to copy the taxonomy from.
Can you provide this information for me. Also the only relationship I see in your settings is the relationship between Docents and Accions formatives
Hi Shane,
OK, I attached screenshots with the information.
When the user "save" a post type "Accions formatives" (witch has a referenced post type "cursos") I want to copy the taxonomy from cursos to accions formatives.