Untitled
unknown
plain_text
a year ago
1.7 kB
1
Indexable
Never
function wpplugin_put_content() { $query = new WP_Query( array( 'post_type' => 'quotes' ) ); $single_titles = array(); foreach($query->posts as $single_post){ $single_titles[] = $single_post->post_title; } $url = 'https://air.hattenbergerpartner.de/quotes-dummy-data.json'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_NOBODY, true); curl_exec($ch); $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); if ($code == 200) { $json = file_get_contents("https://air.hattenbergerpartner.de/quotes-dummy-data.json"); $obj = json_decode($json, true); $titles=array(); foreach($obj['quotes'] as $article_array){ $field_key = 'field_64d5d4479b323'; $title = $article_array['author']; $titles[]=$title ; $content = $article_array['quote']; $category = $article_array['category']; $category_term = term_exists( $category, 'quote_taxonomy', 0 ); if (!$category_term) { $category_term = wp_insert_term( $category, 'quote_taxonomy', array( 'parent' => 0 ) ); } $custom_tax = array( 'quote_taxonomy' => array( $category, ) ); $post = array( 'post_title' => $title, 'post_type' => 'quotes', 'tax_input' => $custom_tax ); foreach ($titles as $value) { print_r($value); print_r($single_titles); if (!in_array($value, $single_titles)) { $id = wp_insert_post($post); wp_set_object_terms($id, $category, 'quote_taxonomy'); // update_field($field_key, $content, $id); } } } } curl_close($ch); }