Created
November 4, 2022 08:47
-
-
Save wpt00ls/e2a41fbc21f93e1bea21e8f2bbd7f96b to your computer and use it in GitHub Desktop.
Gist to add custom meta field & exdend csv importer to import these fields for location post. Divi Multi Location plugin.
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 | |
// Add custom fields to Location post type | |
add_filter( | |
'mlsl_custom_fields', | |
function($fields, $container){ | |
// Add your custom fields by appending to $fields array | |
// Fields Documentation https://docs.carbonfields.net/ (version 3.3.2) | |
$fields[] = \Carbon_Fields\Field::make('text', 'my_custom_field', 'My Custom Field') | |
->set_help_text('Description for my custom field'); | |
return $fields; | |
}, | |
10, | |
2 | |
); | |
// CSV Import post processing after a single location is created. | |
add_action( | |
'mlsl_location_meta_field_import', | |
function($post_id, $data){ | |
// Check if my csv data row has 'URL' column | |
if(isset($data['URL'])){ | |
add_post_meta($post_id, '_my_custom_field', $data['URL'], true); | |
} | |
}, | |
10, | |
2 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment