Save Meta when custom Taxonomy Saves

Support General Save Meta when custom Taxonomy SavesResolved

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #32612
    bfrye@cgmagonline.com[email protected]
    Participant

    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( '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' ); 
    #32635
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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/

    #32636
    bfrye@cgmagonline.com[email protected]
    Participant

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

    #32658
    Long NguyenLong Nguyen
    Moderator

    Hi,

    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.

    #32666
    bfrye@cgmagonline.com[email protected]
    Participant

    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 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.