Created
September 12, 2018 16:22
-
-
Save stevygee/c0db5f535ce780f8e0732423dd4e4ccc to your computer and use it in GitHub Desktop.
The Events Calendar CSV import: Find matching event solely by a custom field. Replace the function match_existing_post() in src\Tribe\Importer\File_Importer_Events.php. In the importer you need to select the column to match by as 'Cost'.
This file contains 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 | |
protected function match_existing_post( array $record ) { | |
global $post; | |
$import_id = $this->get_value_by_key( $record, 'event_cost' ); | |
if ( ! empty( $import_id ) && is_numeric( $import_id ) ) { | |
$args = array( | |
'post_status' => 'any', | |
'post_type' => 'any', // circumvent tribe_events filtering of past events | |
'posts_per_page' => 1, | |
'meta_query' => array( | |
array( | |
'key' => 'ek_import_id', | |
'value' => intval( $import_id ), | |
) | |
) | |
); | |
$get_posts = new WP_Query(); | |
$get_posts->query($args); | |
$matches = array(); | |
if( $get_posts->have_posts() ) : | |
while($get_posts->have_posts()) : | |
$get_posts->the_post(); | |
$matches[] = get_the_ID(); | |
endwhile; | |
endif; | |
// Restore original Post Data | |
wp_reset_postdata(); | |
} | |
if ( empty( $matches ) ) { | |
return 0; | |
} | |
return reset( $matches ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment