• Resolved vtro

    (@vtro)


    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, 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)
  • Hi there @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!

    Hi there @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

    Thanks!

    Thread Starter vtro

    (@vtro)

    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.
Viewing 3 replies - 1 through 3 (of 3 total)

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