Last active
November 22, 2020 10:00
-
-
Save evgrezanov/335ff7283e887d88ca711ca3557d36eb to your computer and use it in GitHub Desktop.
mst_company_jobs_mapping.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'pmxi_saved_post', 'mst_company_jobs_mapping', 10, 1); | |
| function mst_company_jobs_mapping($post_id){ | |
| $import_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['import_id'] ) ? $_GET['import_id'] : 'new' ) ); | |
| if ( $import_id == '161' || $import_id == '145') : | |
| global $wpdb; | |
| // choоse table | |
| $is_test = false; | |
| if ($is_test): | |
| $table_name = "wp_toolset_associations"; | |
| else: | |
| $table_name = "soultm_toolset_associations"; | |
| endif; | |
| $company_name = get_post_meta($post_id, 'wpcf-company-name-temp', true); | |
| if ( !empty($company_name) ): | |
| $page = get_page_by_title($company_name, OBJECT, 'company'); | |
| if (!empty($page)): | |
| // если компания существует, свяжем | |
| $company_id = $page->ID; | |
| //mst_set_company_job_relationship($company_id, $post_id); | |
| $result = $wpdb->insert( | |
| $table_name, | |
| array( | |
| 'relationship_id' => 11, | |
| 'parent_id' => $company_id, | |
| 'child_id' => $post_id, | |
| 'intermediary_id' => 0 | |
| ), | |
| array('%d','%d','%d','%d') | |
| ); | |
| else: | |
| // новая компания - создадим черновик | |
| $company_data = array( | |
| 'post_title' => wp_strip_all_tags( $company_name ), | |
| 'post_content' => 'new company', | |
| 'post_status' => 'draft', | |
| 'post_type' => 'company', | |
| ); | |
| $new_company_id = wp_insert_post( $company_data ); | |
| if( is_wp_error($new_company_id) ){ | |
| error_log(print_r($new_company_id->get_error_message(), false)); | |
| } else { | |
| //mst_set_company_job_relationship($new_company_id, $post_id); | |
| $result = $wpdb->insert( | |
| $table_name, | |
| array( | |
| 'relationship_id' => 11, | |
| 'parent_id' => $new_company_id, | |
| 'child_id' => $post_id, | |
| 'intermediary_id' => 0 | |
| ), | |
| array('%d','%d','%d','%d') | |
| ); | |
| } | |
| endif; | |
| endif; | |
| endif; | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment