The AppThemes themes provided with a built-in listing importer, which allows importing new listings using CSV spreadsheets.
Currently, following themes support the AppThemes Importer feature: ClassiPress, Vantage, Clipper and JobRoller.
Listings can be imported with title, description, excerpt, status, author, date, slug, attachments, Geo data (if theme supports), custom fields, taxonomy terms and even taxonomy meta.
Each theme configures the Importer with a list of fields it should process. Site owners can check out this list by downloading sample CSV file and add their listings for import by adding data in appropriate spreadsheet columns.
The only issue is that site owners can’t just add few more columns in a listings table and expect that the Importer will add this data to new listings.
The Importer doesn’t understand where to add this new data, such as custom fields, taxonomy terms or post core fields.
Hooks Inventory
Developers can use the number of hooks and filters for customizing all steps of listings import:
- ‘
appthemes_before_import_upload_row
‘, - ‘
appthemes_after_import_upload_row
‘, - ‘
appthemes_after_import_upload_form
‘ – action hooks for adding HTML on the Importer form. - ‘
appthemes_importer_import_row_data
‘ – filter for changing imported data for each single listing. This is an array, keyed with types of listing data such as ‘post’, ‘post_meta’, ‘tax_input’, ‘tax_meta’ and valued with arrays of data values. See example below:
array (size=4)
'post' =>
array (size=7)
'post_type' => string 'listing' (length=7)
'post_status' => string 'publish' (length=7)
'post_title' => string 'Sprinkles Cupcakes' (length=18)
'post_content' => string 'We are a Beverly Hills, California-based cupcake bakery chain established in 2005'... (length=553)
'post_author' => string '' (length=0)
'post_date' => string '' (length=0)
'post_name' => string '' (length=0)
'post_meta' =>
array (size=20)
'va_id' => string '1505efb17c8a6187sdssfsadadc' (length=27)
'address' => string '9635 S Santa Monica Blvd, Beverly Hills, CA 90210, USA' (length=54)
'geo_street_number' => string '9635' (length=4)
'geo_street' => string 'South Santa Monica Boulevard' (length=28)
'geo_city' => string 'Beverly Hills' (length=13)
'geo_state_short' => string 'CA' (length=2)
'geo_state_long' => string 'California' (length=10)
'geo_postal_code' => string '90210' (length=5)
'geo_country_short' => string 'US' (length=2)
'geo_country_long' => string 'United States' (length=13)
'phone' => string '(310) 274-8765' (length=14)
'website' => string 'http://sprinkles.com/locations/california/beverly-hills/cupcakes' (length=64)
'email' => string '' (length=0)
'_listing_duration' => string '30' (length=2)
'google-plus' => string '+sprinkles' (length=10)
'facebook' => string 'sprinkles' (length=9)
'twitter' => string 'sprinkles' (length=9)
'instagram' => string 'sprinklescupcakes' (length=17)
'youtube' => string 'sprinkles' (length=9)
'pinterest' => string '' (length=0)
'tax_input' =>
array (size=2)
'listing_category' =>
array (size=1)
0 => string 'Dessert' (length=7)
'listing_tag' =>
array (size=3)
0 => string 'Cupcakes' (length=8)
1 => string 'Bakeries' (length=8)
2 => string 'Desserts' (length=8)
'tax_meta' =>
array (size=0)
empty
- ‘
appthemes_importer_import_row_post
‘ – filter, similar to previous one, but intended only for changing ‘post’ data. - ‘
appthemes_importer_import_row_post_meta
‘ – filter, similar to previous one, but intended only for changing ‘post_meta’ data. - ‘
appthemes_importer_import_row_after
‘ – action hook to do anything after importing row. It has two arguments$post_id
and$row
.
In addition, each theme provides with a personal filter for changing the importing data structure. Such as adding new custom fields columns or taxonomies:
- ‘
cp_csv_importer_args
‘ – for ClassiPress - ‘
va_csv_importer_args
‘ – Vantage - ‘
jr_csv_importer_args
‘ – JobRoller - ‘
clpr_csv_importer_args
‘ – Clipper
Usage Examples
Examples provided with code snippets which you can add in a custom plugin or child theme functions.php file. Alternatively, Code Snippets plugin can be used (more details in the instruction).
1. Add Yoast SEO meta fields using ‘appthemes_importer_import_row_after’ hook.
This hook works the same for all themes from the list above.
Add 3 new columns to your import CSV file:
_yoast_wpseo_metadesc
– For Yoast SEO meta description_yoast_wpseo_title
– Meta title_yoast_wpseo_focuskw
– Focus keywords
Fill columns with values.
Add following PHP code on your site:
function arthemes_importer_import_row_after( $post_id, $row ) {
$yoast_fields = array(
'_yoast_wpseo_metadesc',
'_yoast_wpseo_title',
'_yoast_wpseo_focuskw',
);
foreach ( $yoast_fields as $yoast_field ) {
if ( ! empty( $row[ $yoast_field ] ) ) {
update_post_meta( $post_id, $yoast_field, $row[ $yoast_field ] );
}
}
}
add_action( 'appthemes_importer_import_row_after', 'arthemes_importer_import_row_after', 10, 2 );
2. Add Yoast SEO meta fields using theme filters.
You can do the same as in example above, but using theme specific filters. This is just an alternative way for example purposes.
So add Yoast SEO fields columns in your CSV file and fill values.
Add following PHP code on your site:
function arthemes_csv_importer_args( $args ) {
$args['custom_fields'] = array_merge( $args['custom_fields'], array(
'_yoast_wpseo_metadesc' => '_yoast_wpseo_metadesc',
'_yoast_wpseo_title' => '_yoast_wpseo_title',
'_yoast_wpseo_focuskw' => '_yoast_wpseo_focuskw',
) );
return $args;
}
// For ClassiPress
add_filter( 'cp_csv_importer_args', 'arthemes_csv_importer_args' );
// For Vantage
add_filter( 'va_csv_importer_args', 'arthemes_csv_importer_args' );
// For JobRoller
add_filter( 'jr_csv_importer_args', 'arthemes_csv_importer_args' );
// For Clipper
add_filter( 'clpr_csv_importer_args', 'arthemes_csv_importer_args' );
3. Add custom taxonomy meta fields using theme filters.
Similarly to the previous example, you can add custom fields to taxonomy terms. The following example shows how to add an email field to the Clipper Store.
Use the form builder (Clipper -> Forms) to add a new custom field to the Store form. Save, and you will see the field meta name (for instance app_email
).
Then add “email” column in your CSV file and fill values.
Add following PHP code on your site:
function arthemes_org_csv_importer_args( $args ) {
$args['tax_meta']['stores'] = array_merge( $args['tax_meta']['stores'], array(
'email' => 'app_email',
) );
return $args;
}
add_action( 'clpr_csv_importer_args', 'arthemes_org_csv_importer_args' );
Conclusion
The filters and hooks above allows to completely control the listing import and add or generate all necessary data. So if you need more examples or explanations just let us know in comments.