v.2.1.6
* fixed acf fields missing on select phase when first item doesn't have those fields
v2.1.3
* added support for acf file field
v2.1.2
* fixed post metas not included on import
v2.1.1
* fixed other acf fields not included on import
v2.1.0
* added support for nested terms
Settings page at Tools > FF Export / FF ImportĀ
add_filter( 'ff_export_types', function( $types ){
$types['custom_1'] = 'Custom 1';
return $types;
});
The custom type should show up under select type dropdown
add_filter( 'ff_export_data_{custom_slug}', function( $items, $ff_export ){
// store the items in the $items array
// $ff_export is the class instance that contains helpful methods, you can check all the methods at export/class-export.php
// codes here ...
return $items;
}, 10, 2 );
sample codes:
add_filter( 'ff_export_data_custom_1', function( $items, $ff_export ){
$args = [
'post_type' => 'property',
'showposts' => -1,
];
$q = new WP_Query($args);
foreach( $q->posts as $post ) {
$item = [
'post_data' => $post,
];
// featured image
$item['featured_image'] = $ff_export->get_featured_image_url($post->ID);
// acf fields
$item['acf_fields'] = $ff_export->get_acf_fields( $post->ID );
// all post meta
$item['post_metas'] = get_post_meta($post->ID);
// taxonomies
$taxonomies = [
'custom_category',
'property_cat',
];
$item['taxonomies'] = $ff_export->get_taxonomy_terms( $post->ID, $taxonomies );
$items[] = $item;
}
return $items;
}, 10, 2 );
add_filter( 'ff_import_custom_types', function( $types ){
$types['custom_1'] = 'Custom 1';
return $types;
});
A new tab “Custom” will show up, the custom type should be under the select type dropdown
add_action('ff_import_data_{custom_slug}', function($item, $ff_import){
// $item contains the data for each individual item - check the preview to see what it looks like
// $ff_import is the class instance that contains helpful methods, you can check all the methods at import/class-import.php
// codes here...
}, 10, 2);
Sample Codes:
add_action('ff_import_data_custom_1', function($item, $ff_import){
$post_type = 'property';
$post_title = $item['post_data']['post_title'];
// check if post exists
$post_id = $ff_import->get_post_id( $post_title, $post_type );
if( !$post_id ) {
// create new post
$post_id = wp_insert_post([
'post_title' => $post_title,
'post_status' => 'publish',
'post_type' => $post_type,
]);
}
if( !$post_id ) return;
// upload featured image
$ff_import->update_post_thumbnail( $post_id, $item['featured_image'] );
// post metas
$metas = [];
// image / gallery
// get image ids, upload new images
// string of single image url OR array of image urls
$img_ids = $ff_import->get_image_ids( SINGLE_IMAGE_URL_OR_ARRAY_OF_IMAGES );
if( $img_ids ) {
$metas['META_KEY_HERE'] = $img_ids;
}
// post objects
$map_to_post_type = 'post';
// string of single post title OR array of post titles
$post_object_ids = $ff_import->get_post_ids_from_title( POST_TITLE_OR_ARRAY_OF_POST_TITLES, $map_to_post_type );
if( $post_object_ids ) {
$metas['META_KEY_HERE'] = $post_object_ids;
}
// save post metas
$ff_import->update_post_metas( $post_id, $metas );
// taxonomies / terms
$terms = ARRAY_OF_TERM_NAMES_HERE;
$map_to_taxonomy = 'category';
$append = true; // true = add | false = replace existing
$ff_import->assign_terms( $post_id, $terms, $map_to_taxonomy, $append );
}, 10, 2);
Select your desired option below to share a direct link to this page.
Your friends or family will thank you later.