Posts importeren (WordPress): verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(Nieuwe pagina aangemaakt met '== Voorbeeld: Vanuit dwh + Mikado == Dit komt uit de zomer van 2019. Iets met bellen: <pre> <?php # # Import posts into example.com #############################...') |
|||
(Een tussenliggende versie door dezelfde gebruiker niet weergegeven) | |||
Regel 7: | Regel 7: | ||
<?php | <?php | ||
# | # | ||
− | # Import posts into | + | # Import posts into a site, including Mikado-options |
############################################################### | ############################################################### | ||
# | # | ||
Regel 177: | Regel 177: | ||
} | } | ||
</pre> | </pre> | ||
+ | |||
+ | == Zie ook == | ||
+ | |||
+ | * [[Automatisering (WordPress)]] |
Huidige versie van 10 jul 2019 om 12:31
Voorbeeld: Vanuit dwh + Mikado
Dit komt uit de zomer van 2019. Iets met bellen:
<?php # # Import posts into a site, including Mikado-options ############################################################### # echo "\n\n"; echo "###############################################################\n"; echo "# import-posts - Start ########################################\n"; echo "###############################################################\n\n"; ############################################################### # Process input arguments ############################################################### # # * $site_path: To connect with the correct API # * #site_url: For sideloading images # * $post_table: Where data is stored in the dwh # echo "\nProcess input arguments...\n"; # # Argument #01 is the command itself. Hence the count of arguments # should be 1 higher than expected # $site_path= $argv[1]; echo " site_path: ".$site_path."\n"; $site_url = $argv[2]; echo " site_url: ". $site_url. "\n"; $post_table_name = $argv[3]; echo " post_table_name: ". $post_table_name. "\n"; $verbose = $argv[4]; echo " verbose: ". $verbose. "\n"; $db_name = $argv[5]; echo " db_name: ". $db_name. "\n"; $db_user = $argv[6]; echo " db_user: ". $db_user. "\n"; $db_password = $argv[7]; echo " db_password: ". $db_password. "\n"; ############################################################### # Set variables ############################################################### # # Nothing to set here ############################################################### # Load libraries ############################################################### # echo "\nLoad libraries...\n"; # require_once($site_path . "/wp-load.php"); require_once($site_path . '/wp-admin/includes/media.php'); require_once($site_path . '/wp-admin/includes/file.php'); require_once($site_path . '/wp-admin/includes/image.php'); require_once('/home/strompf/Dropbox/Scripts/php/dvb_functions.php'); require_once('/home/strompf/Dropbox/Scripts/php/dvb_wordpress_functions.php'); ############################################################### # Connect with dwh ############################################################### # echo "\nConnect with dwh...\n"; # $conn = create_pdo_object($db_name, $db_user, $db_password); ############################################################### # Fetch post table from dwh ############################################################### # echo "\nFetch post table from dwh...\n"; # $post_table = fetch_table($conn, $post_table_name); # print_r($post_table); # die; ############################################################### # Loop through post_table rows ############################################################### # echo "\nLoop through post_table rows...\n"; echo "###############################\n"; foreach ($post_table as $key => $post_table_row) { if (isset($verbose)) { echo " Uploading posts - Title current post: ".$post_table_row['title_nl']."\n"; echo " index $key: ".$key."\n"; } # Upload product, return updated $post_table_row ##################################################### # $post_table_row=process_post_table_row($post_table_row); } ############################################################### # Finish ############################################################### # echo "\n\n"; echo "###############################################################\n"; echo "# import-products - Finish ####################################\n"; echo "###############################################################\n\n"; function process_post_table_row($post_table_row) { ############################################################### # process_post_table_row($post_table_row) ############################################################### # # Form $product_array for use with "wp_insert_post" ##################################################### # echo "Function process_post_table_row...\n"; # $post_array_tmp=array ( 'post_title' => $post_table_row['title_nl'], 'post_content' => $post_table_row['content_nl'], 'post_name' => $post_table_row['slug_nl'], 'post_status' => 'publish', 'post_type' => 'page', 'post_author' => 1 ); # Insert post, get post_id in return ########################################## # $post_id = wp_insert_post($post_array_tmp); echo "post_id: ".$post_id."\n"; # Set meta fields ########################################## # update_post_meta($post_id, '_yoast_wpseo_title', $post_table_row['yoas_seo_title']); update_post_meta($post_id, '_yoast_wpseo_metadesc', $post_table_row['yoast_seo_description']); update_post_meta($post_id, '_yoast_wpseo_focuskw', $post_table_row['keyphrase_nl']); update_post_meta($post_id, 'mkd_show_title_area_meta', $post_table_row['mkd_show_title_area_meta']); update_post_meta($post_id, 'mkd_title_area_background_image_meta', $post_table_row['mkd_title_area_background_image_meta']); update_post_meta($post_id, 'mkd_title_area_background_image_responsive_meta', $post_table_row['mkd_title_area_background_image_responsive_meta']); update_post_meta($post_id, 'mkd_title_area_subtitle_meta', $post_table_row['mkd_title_area_subtitle_meta']); update_post_meta($post_id, 'mkd_subtitle_color_meta', $post_table_row['mkd_subtitle_color_meta']); # Language ########################################## # pll_set_post_language($post_id, 'nl'); # Update $post_table_row with post_id ########################################## # $post_table_row['post_id'] = $post_id; return $post_table_row; }