Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stevygee/c0db5f535ce780f8e0732423dd4e4ccc to your computer and use it in GitHub Desktop.
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'.
<?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