Map Additional Custom Fields from Feeds

Map Additional Custom Fields from Feeds

For most feeds, Go Fetch Jobs matches RSS feeds standard tags like: location, geolocation, latitude, longitude, company, logo and maps them to the respective database field. 

Feeds can contain other tags but since Go Fetch Jobs does not have info on how they should be mapped into the database it skips them. You’ll need to do some custom setup to help Go Fetch Jobs (GOFJ) map to import other tags and map them to their respective custom field. You can achieve this in two steps:

  1. Informing GOFJ about the custom tags you want to import
  2. Informing GOFJ on how to map the new tags with custom fields

This will require adding custom code to your theme functions.php file or through a plugin that allows adding custom code like Code Snippets.

As an example, we’ll be importing two fields named:

  • salary (considering the RSS feed contains a <salary></salary> tag)
  • state (considering the RSS feed contains a <state></state> tag)

The example assumes you have the following custom field names:

  • salary
  • state

Important: Tag names are case sensitive. Make sure they match the names displayed on the feed.

1. Identifying the new tags

To inform GOFJ about the new tags you just need to paste this snippet: 

/*
 * Add support for new RSS tags (i.e: , ).
 */
add_filter( 'goft_wpjm_providers_valid_item_tags', 'my_custom_tags' );
function my_custom_tags( $fields ) {
  $fields[] = 'state';
  $fields[] = 'salary';
  return $fields;
}

2. Mapping the fields

Now that the tag are known by GOFJ you should immediately seem them on the sample table, if the RSS feed provides them. We just need to tell GOFJ how to map the tags to database fields.

/**
 * Maps the custom fields to the related RSS tag item values.
 */
add_filter( 'goft_wpjm_import_item_params', 'my_custom_tags_values', 10, 2 );
function my_custom_tags_values( $params, $item ) {

  // Check if the 'state' tag is a valid RSS item tag.
  if ( ! empty( $item['state'] ) ) {
    // The string name on the left must match your cystom field name.
    // The string on the right must match the RSS tag name.
    //
    // i.e: $params['meta']['the_custom_field_name'] = $item['the_related_rss_tag_name']
    $params['meta']['state'] = $item['state'];
  }

  if ( ! empty( $item['salary'] ) ) {
    // Works as explained above to the 'salary field'.
    $params['meta']['salary'] = $item['salary'];
   }
   return $params;
}

This snippet will:

  1. check if the RSS feed contain a <state> or <salary> tag
  2. considering that the custom fields names are ‘state’ and ‘salary’ respectively, it will map them *

(*) If your custom fields don’t match the tag names (<salary> = ‘salary’) you just need to change them accordingly. For example, if your ‘state‘ custom field is called ‘location-state‘ you would just change the code to use that field. The same applies to the tag name. Just make sure both the tag and custom fields match the RSS feed tag name and your DB custom fields.

Conclusion

Thats it! You should now be able to import these two new fields for RSS feeds that support them.