Skip to main content
All CollectionsPersonal websitesWordPress
WordPress: Using custom fields
WordPress: Using custom fields

Connecting custom fields to your website.

Gregory Claeyssens avatar
Written by Gregory Claeyssens
Updated over 2 months ago

Custom fields allow you to extend the default functionality offered by StoryChief.
Check out this in-depth article on how and why to use custom fields.

When using external custom fields, you'll need to map these over to your WordPress blog as well. There are 2 ways of doing this.

Table of Contents


Start using custom fields

1. Basic mapping with ACF

If you are using the Advanced Custom Fields (ACF) plugin on a WordPress website, you can connect your custom fields to ones in your StoryChief account.

Step 1. Make sure that you already have ACF installed. Now download, install, and activate the StoryChief ACF plugin on your WordPress site.

Step 2. In the admin site of WordPress, go to Settings ➜ StoryChief ACF.

Step 3. Now you can link custom fields to ones in WordPress. Click on "Save changes".

πŸ”” Note: If you don't see any available fields here, visit your WordPress channel page in StoryChief and click on edit for your website. This allows the new custom field(s) to be sent to WordPress, you don't need to change anything.

Done πŸŽ‰ Your custom fields will now be mapped when publishing to WordPress.

2. Extended mapping with WordPress actions.

Using the available plugin actions and filters you can extend the way our plugin behaves. Below are some examples of how to map the fields. A complete overview of the available hooks and filters can be found here.

/**
* StoryChief custom code to set the related articles field
*/
function storyChiefSetRelatedArticles($payload)
{
$STORYCHIEF_RELATED_ARTICLES_FIELD_KEY = 'TheKeyGivenFromStoryChief';
$WORDPRESS_RELATED_ARTICLES_FIELD_KEY = 'the_custom_field_key_from_wordpress';

$raw_value = storyChiefGetCustomFieldValue($payload, $STORYCHIEF_RELATED_ARTICLES_FIELD_KEY);
$postId = $payload['external_id'];

if(!is_null($raw_value)) {
// Do any kind of work here

// When using ACF plugin (Use update_post_meta for others)
update_field($WORDPRESS_RELATED_ARTICLES_FIELD_KEY, $raw_value, $postId);
} else {
// When using ACF plugin (Use delete_post_meta for others)
delete_field($WORDPRESS_RELATED_ARTICLES_FIELD_KEY, $postId);
}
}
add_action('storychief_after_publish_action', 'storyChiefSetRelatedArticles');


/**
* Helper function to get a custom field value by key
*/
function storyChiefGetCustomFieldValue($payload, $field_key) {
foreach ($payload['custom_fields'] as $customField) {
if ($customField['key'] === $field_key && $customField['value']) {
return $customField['value'];
}
}
return null;
}


πŸ“š Next steps

Did this answer your question?