terms – wp_insert_term doesn’t want to enter its data into custom taxonomy

Question

so I’m working on a code to take data from an array and put it in a custom taxonomy using wp_insert_tem, but the data won’t go in. this is the json i want to fetch, this is from a url

{
"genres": [
    {
      "name": "Military"
    },
    {
      "name": "Sci-fi"
    },
    {
      "name": "Shounen"
    }
  ],
}

this is the code i made

$result = file_get_contents($url);
$array = json_decode($result, true);
foreach($array['genres'] as $gen){
    wp_insert_term(
        $gen["name"],
        "genres",
        array(
            "description" => "",
            "slug" => sanitize_title($gen["name"]),
        ),
   );
}

please help me

0
Soelllll 2 weeks 2021-09-05T21:54:52-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse