I see two ways to do this:
Automatically: by Matching AUTOR term name to TEAM post title
Assuming the autor’s terms are the same as the custom post type team
post titles, you could find the relation with code like:
function show_product_autor(){
// get this woo-comm's product author
$authors = wp_get_post_terms( get_the_ID() , 'autor' );
// we know it'll just be one author, so use first object of array
$author = array_pop($authors);
// knowing the authors name, lets find the TEAM page
$authorTeamPg = get_page_by_title( $author->name, 'OBJECT', 'team' );
// now we know the authors page
$authorTeamPgLink = get_permalink( $authorTeamPg->ID);
// output
echo "Author: <a href="https://wordpress.stackexchange.com/questions/289244/{$authorTeamPgLink}">{$author->name}</a>";
}
The above has no error handling for if a match was not found, but it’s easy enough to code in. However, in your example you sent, the term name is Elena Farini
and the custom post type team is Farini Elena
. So this code would fail you unless you ensure the names match in the backend. The alternative (so you don’t need to make sure of text matching), is to work with ID’s and manually make the relation from term to team member, so:
Manually: by assigning a TEAM ID to an AUTOR’s term meta
For autor
you need to use _term_meta
and create a drop-down field listing authors with value of their IDs. That will create a relation from an autor
term’s, to the ID of a team
member.
Here’s a good article on setting up the term meta feilds.
Once setup, in show_product_autor()
you’d do somthing like this:
function show_product_autor(){
// get this woo-comm's product author
$authors = wp_get_post_terms( $post->ID, 'autor' );
// we know it'll just be one author, so use first object of array
$author = array_pop($authors);
// get the team page ID from _term_meta for this term author
$authorTeamID = get_term_meta( $author->term_id, 'autor', true );
// get the full TEAM page for this author
$authorTeamPg = get_post( $authorTeamID );
// now we know the authors page
$authorTeamPgLink = get_permalink( $authorTeamPg->ID);
// output
echo "Author: <a href="https://wordpress.stackexchange.com/questions/289244/{$authorTeamPgLink}">{$authorTeamPg->post_title}</a>";
}