1. Go to this page and download the library: Download hard-g/cpt-tax library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Fetch the term ID corresponding to the Actor post.
$actor_term_id = \HardG\CptTax\Registry::get_term_id_for_post_id( 'actors', $actor_post_id );
wp_set_object_terms( $movie_post_id, [ $actor_term_id ], 'actor_tax', true );
// Fetch the term ID corresponding to the Actor post.
$actor_term_id = \HardG\CptTax\Registry::get_term_id_for_post_id( 'actors', $actor_post_id );
$movies_with_actor = get_posts(
[
'post_type' => 'movie_pt',
'tax_query' => [
[
'taxonomy' => 'actor_tax',
'terms' => $actor_term_id,
]
],
]
);
register_taxonomy(
'my_taxonomy',
$my_post_types,
[
// ...
'public' => false,
'show_ui' => false, // Unless you want to be able to see it for diagnostic purposes in the Dashboard
'show_in_rest' => false,
// ...
]
);