Some of our users have job data stored in custom fields in their ATS that they would like to add to their syndication feeds. This can be done using the following action:
<?php
/**
* Feed Extras Each
*
* Add additional content to the feed each job items. Dynamically named for each feed.
*
* @wordpress-action
*
* @since 2.0.1
*
* @param int $wpid The ID of the WordPress job posting post
*/
do_action( "matador_extension_feeds_{$feed}_each", get_the_ID() );
?>
By hooking a function to this action we can echo out the desired XML for a custom field. Here is an example of adding the value of a fied caled ‘myCustomFieldName’ to the Xtramile feed:
function add_my_custom_field( $wpid ) {
// Retrieve the value for the custom field.
$custom_field_value = get_post_meta( $wpid, 'myCustomFieldName' );
if ( ! empty( $custom_field_value ) ) {
// print the custom field value in XML tags of your choosing
printf( '<customFieldTag>%s</customFieldTag>', matador_feeds_xml( $custom_field_value, [ 'echo' => false ] ) );
}
}
add_action( 'matador_extension_feeds_xtramile_each', 'add_my_custom_field' );
Now when we check our Xtramile xml feed we see that our custom field is present in the feed:
