1. Home
  2. Matador Extensions
  3. Syndication XML Feeds
  4. Adding Custom Fields to an Existing Feed

Adding Custom Fields to an Existing Feed

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() );
	?>

You should add your version of the following code to your child theme – for more details on where exactly it should go in your child theme see here

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:

Updated on May 2, 2024
Was this article helpful?

Related Articles

Need Support?
Can't find the answer you're looking for?
Contact Support