Save Meta when custom Taxonomy Saves
- This topic has 4 replies, 2 voices, and was last updated 3 years, 4 months ago by
[email protected].
-
AuthorPosts
-
December 14, 2021 at 10:06 PM #32612
[email protected]
ParticipantI am in need of some advice, we are setting up a custom tag for Movies. We want to have it pull from the OMDB Api when it is saved. We have the function setup, but it is not firing, and I am stumped.
I am trying to have this call when I save the custom taxonomy, so it populates the info needed for the details.
Is there is something I am missing, please let me know,
thanks for all the help!
// define the edit_terms callback function action_terms($term_id) { $api_key = 'xxxxxx'; $term = $term_id; //$imdb_id = get_field('imdb_id', $term_id); $imdb = get_term_meta( $term_id, 'imdb_id', true ); //$imdb_title = get_field('ent_imdb_title', $term_id); $request = wp_remote_get( 'http://www.omdbapi.com/?&apikey='.$api_key.'&i='.$imdb ); $body = wp_remote_retrieve_body( $request ); $data = json_decode( $body ); $title = $data->Title; $plot = $data->Plot; $released = $data->Released; $director = $data->Director; //$genres = $data->Genre; $runtime = $data->Runtime; $actors = $data->Actors; $country = $data->Country; $language = $data->Language; //$poster = $data->Poster; //rwmb_set_meta( $term_id, 'description', $plot); //rwmb_set_meta( $term_id, 'blu_review_name', $title); rwmb_set_meta( $term, 'movie_premiere_date', $released); rwmb_set_meta( $term_id, 'movie_detail_directors', $director); //rwmb_set_meta( $term_id, 'film_genre', $genres); rwmb_set_meta( $term_id, 'movie_running_time', $runtime); rwmb_set_meta( $term_id, 'cast', $actors); //rwmb_set_meta( $term_id, 'country', $country); //rwmb_set_meta( $term_id, 'language', $language); //rwmb_set_meta( $term_id, 'product_image', $poster); BugFu::log($actors); }; // add the action add_action( 'edit_termd', 'action_terms' );
December 15, 2021 at 11:19 AM #32635Long Nguyen
ModeratorHi,
The helper function
rwmb_set_meta()
works only when the field is already registered. In Meta Box, fields are registered at hook init with priority 20. So, you need to run this function after that:add_action( 'init', function() { rwmb_set_meta( 12, 'my_field', 'my_value' ); }, 99 );
Or you can use the function
update_term_meta()
to set the term meta https://developer.wordpress.org/reference/functions/update_term_meta/December 15, 2021 at 11:26 AM #32636[email protected]
ParticipantCan metabox fields be edited by the
update_term_meta()
function?December 15, 2021 at 6:53 PM #32658Long Nguyen
ModeratorHi,
Yes. The Meta Box helper function
rwmb_set_meta()
or WordPress functionupdate_term_meta()
helps you to update the value in the database. It does not relate to Meta Box or other plugins which create the custom field.December 16, 2021 at 3:06 AM #32666[email protected]
ParticipantOkay made changes, but for some reason, the method still does not change on save, and I am stumpped. I could get it working with ACF, not sure why it would be harder in Metabox
-
AuthorPosts
- You must be logged in to reply to this topic.