Le snippet du tutoriel youTube Make Crocoblock JetEngine
pierre@carbonnel-media.com·16 mai 2024·0 commentaire
// Define your webhook endpoint
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v1', '/get_term_name/', array(
'methods' => 'GET',
'callback' => 'get_term_name_by_id',
) );
});
// Function to retrieve term name by ID
function get_term_name_by_id( $data ) {
$term_id = $data['id']; // Assuming you're passing the term ID via the URL parameter 'id'
// Check if the term exists
$term = get_term( $term_id );
if ( ! $term || is_wp_error( $term ) ) {
return new WP_Error( 'term_not_found', 'Term not found', array( 'status' => 404 ) );
}
return $term->name;
}