2
votes

I wrote some scripts to add the custom image field to the custom taxonomy that I registered.

The problem is now I'm trying to get the term meta data, by the way since the add_term_meta function is introduced from version 4.4 of wordpress I can't use this function.

Now I'm using wordpress version 4.2 for the website cause of there are bunch of custom plugins and scripts there.

Which function I have to use to get the term meta data on version 4.2?

** EDIT **

add_action( 'created_hr50_amenity', 'save_hr50_amenity_image', 10, 2 );

function save_hr50_amenity_image ( $term_id, $tt_id ) {
   if( isset( $_POST['hr50_amenity-image-id'] ) && '' !== $_POST['hr50_amenity-image-id'] ){
     $image = $_POST['hr50_amenity-image-id'];

     // ** add_term_meta ** WHAT CAN I USE INSTEAD OF THIS FUNCTION? **
     add_term_meta( $term_id, 'hr50_amenity-image-id', $image, true );

     // var_dump(get_term_meta( $term_id, 'hr50_amenity-image-id'));
   }
}
1

1 Answers

3
votes

Can't you just copy the add_term_metaand name it something like compat_add_term_meta and use it with 4.2 WP?

You have the entire function here: https://developer.wordpress.org/reference/functions/add_term_meta/

You can use a conditional then:

if ( version_compare( $GLOBALS['wp_version'], '4.2', '<=' ) ) {
    compat_add_term_meta();
} else {
    add_term_meta();
}

So that it works in both cases.

Take in mind that you'd probably have to add wp_term_is_shared as well, other than that all the other functionality exists.

Also not 100% sure but check out how the database schema looks like. It's also possible that some tables are missing (term meta) so these should be created as well (can be done through $wpdb class tho).