Title: How to reference custom fields in custom shortcode?
Last modified: August 14, 2019

---

# How to reference custom fields in custom shortcode?

 *  Resolved [vtro](https://wordpress.org/support/users/vtro/)
 * (@vtro)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/how-to-reference-custom-fields-in-custom-shortcode/)
 * Custom fields can be called in the designer using shortcodes such as `[subscriber:
   cf_2]`.
 * However, when creating a custom shortcode as described on [https://kb.mailpoet.com/article/160-create-a-custom-shortcode](https://kb.mailpoet.com/article/160-create-a-custom-shortcode),
   it doesn’t seem possible to access this custom field using `$subscriber->cf_2`
   as one could come to expect.
 * Just a little background: Basically, I’m trying to differentiate between male
   and female subscribers and change certain content such as the salutation dynamically.
   I don’t see a possibility of doing that without access to the custom field but
   I’m open to suggestions.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Wysija](https://wordpress.org/support/users/wysija/)
 * (@wysija)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/how-to-reference-custom-fields-in-custom-shortcode/#post-11835555)
 * Hi there [@vtro](https://wordpress.org/support/users/vtro/),
 * It should work. We don’t support custom code, but if you can share a pastebin
   to your code, we can take a quick look and see if there’s anything obvious you’re
   missing.
 * Thanks!
 *  [Wysija](https://wordpress.org/support/users/wysija/)
 * (@wysija)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/how-to-reference-custom-fields-in-custom-shortcode/#post-11844946)
 * Hi there [@vtro](https://wordpress.org/support/users/vtro/),
 * We’ve been testing and there’s one important thing to note, before you’ll be 
   able to access the custom fields data, you’ll need to make sure the custom fields
   are loaded.
 * You can do this by using the `getSubscriberFields()` function as detailed here:
   [https://github.com/mailpoet/mailpoet/blob/master/doc/api_methods/GetSubscriberFields.md](https://github.com/mailpoet/mailpoet/blob/master/doc/api_methods/GetSubscriberFields.md)
 * Thanks!
 *  Thread Starter [vtro](https://wordpress.org/support/users/vtro/)
 * (@vtro)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-reference-custom-fields-in-custom-shortcode/#post-11853783)
 * Hi,
 * Thanks for the answer. Somehow I missed your first answer from 5 days ago and
   only received a notification about the second.
 * I tried calling `getSubscriberFields()` within the function `mailpoet_custom_shortcode(
   $subscriber)` directly but that doesn’t seem to work, I had to initialize the
   API first. Even then, this would not just extend the accessible fields of the`
   $subscriber` object, I could only access custom fields using the API function`
   getSubscriber()`.
 * Which is perfectly fine, though – main thing it works now!
 * Cheers
    -  This reply was modified 6 years, 10 months ago by [vtro](https://wordpress.org/support/users/vtro/).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to reference custom fields in custom shortcode?’ is closed to new
replies.

 * ![](https://ps.w.org/mailpoet/assets/icon-256x256.png?rev=3284564)
 * [MailPoet - Newsletters, Email Marketing, and Automation](https://wordpress.org/plugins/mailpoet/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailpoet/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailpoet/)
 * [Active Topics](https://wordpress.org/support/plugin/mailpoet/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailpoet/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailpoet/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [vtro](https://wordpress.org/support/users/vtro/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/how-to-reference-custom-fields-in-custom-shortcode/#post-11853783)
 * Status: resolved