Sunday, February 12, 2023
HomeWordPress Developmentphrases - Unable to import term_meta in wordpress utilizing wp_cron

phrases – Unable to import term_meta in wordpress utilizing wp_cron


I’ve imported cities as time period named as sf-cities I am attempting so as to add international locations title as time period meta I’ve connected pattern of my code.

add_action( 'event_notification', 'import_countries', 10, 0 );
perform import_countries(){
    $response = wp_remote_get('https://uncooked.githubusercontent.com/russ666/all-countries-and-cities-json/grasp/international locations.json');
    $response_body = wp_remote_retrieve_body( $response );
    $international locations = json_decode($response_body);
    
    $last_id = 0;
    
    $phrases = get_terms( array(
        'taxonomy' => 'sf-cities',
         'hide_empty' => false,
    )); 
    $depend = 1;
    foreach($international locations as $nation => $cities) {
        foreach($cities as $metropolis) {
            $time period = get_term_by('title', $metropolis, 'sf-cities');
            if( $depend == 1000 ) {
                $depend = 1;
                usleep(500);
            }
            if(!empty( $time period )) {
                if( $term->term_id > 220 ) { 
                    if( empty( get_term_meta( $term->term_id , 'nation', true) )) {
                        add_term_meta( $term->term_id ,'nation', $nation );       
                    } else {
                        update_term_meta( $term->term_id ,'nation', $nation );        
                    }
                    
                } 
                $last_id = $term->term_id;
            } else {
                proceed;
            }
            $depend++;
        }
    }
    return $last_id;
}

Even it was working within the json file there are 80k information in there. Is there another chance so as to add time period meta worth with out cron job.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments