Custom Fields
Support General Save Meta when custom Taxonomy Saves

  • Creator
  • #32612

    I 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( ''.$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);   
    // add the action 
    add_action( 'edit_termd', 'action_terms' ); 
Viewing 4 replies - 1 through 4 (of 4 total)
  • Author
  • #32635
    Long Nguyen


    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


    Can metabox fields be edited by the update_term_meta() function?

    Long Nguyen


    Yes. The Meta Box helper function rwmb_set_meta() or WordPress function update_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.


    Okay 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

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.