/** * 4. Import Data and Update ACF - REVISED FOR CONTAINS MATCH * NOTE: This is the section you MUST customize for your fields. */ function tsv_acf_import_data( $data ) { $success_count = 0; $fail_count = 0; foreach ( $data as $row ) { // --- 🎯 STEP 1: Identify the Post to Update (REVISED) --- // CHANGE 'post_title' to match your TSV column header if it's different! $post_identifier_text = isset( $row['post_title'] ) ? sanitize_text_field( $row['post_title'] ) : ''; $post_id = 0; if ( ! empty( $post_identifier_text ) ) { // **REVISED LOGIC: Search for posts whose title CONTAINS the identifier text** $args = array( 'post_type' => 'post', // Change 'post' to your Custom Post Type slug if necessary 'post_status' => 'any', 's' => $post_identifier_text, // 's' is the search parameter 'posts_per_page' => 1, // Only need the first match 'fields' => 'ids', // Return only post IDs for efficiency ); // Execute the search query $matching_posts = get_posts( $args ); if ( ! empty( $matching_posts ) ) { // We take the ID of the first matching post found $post_id = $matching_posts[0]; } } // Check if a post was found before proceeding if ( $post_id > 0 ) { // --- 🎯 STEP 2: Update the ACF Fields --- // **MAP YOUR TSV COLUMNS (e.g., $row['tsv_column_header'])** // **TO YOUR ACF FIELD KEYS/NAMES (e.g., 'your_acf_field_name')** // Example 1: Simple Text/Number Field if ( isset( $row['product_price'] ) ) { $value = sanitize_text_field( $row['product_price'] ); update_field( 'product_price', $value, $post_id ); } // Example 2: Simple Text/Number Field if ( isset( $row['stock_status'] ) ) { $value = sanitize_text_field( $row['stock_status'] ); update_field( 'stock_status', $value, $post_id ); } // Add more field mappings as needed... $success_count++; } else { $fail_count++; // Log which identifier failed to match a post error_log( 'ACF Importer failed to find post containing: ' . $post_identifier_text ); } } // --- 🎯 STEP 3: Display Results --- echo '

✅ **Import Complete!** ' . $success_count . ' posts updated successfully. ' . $fail_count . ' posts failed to match.

'; }
Warning: Cannot modify header information - headers already sent by (output started at /home/ccmrihc/public_html/wp-content/plugins/tsv-acf-importer/tsv-acf-importer.php:1) in /home/ccmrihc/public_html/wp-includes/sitemaps/class-wp-sitemaps-renderer.php on line 126
https://ccmri.hcmr.gr/wp-sitemap-posts-post-1.xmlhttps://ccmri.hcmr.gr/wp-sitemap-posts-page-1.xmlhttps://ccmri.hcmr.gr/wp-sitemap-taxonomies-category-1.xmlhttps://ccmri.hcmr.gr/wp-sitemap-users-1.xml