LogoLogo
WordPress.orgExtensionsSupport
Version 9
Version 9
  • Notification – Custom Notifications and Alerts for WordPress
  • Updating to v9
  • Known issues
  • πŸ€Έβ€β™€οΈ User guide
    • Update broke my site
    • How Notification plugin works
    • Who can use this plugin
    • How to create Notifications
    • Troubleshooting
    • Advanced
      • How to escape { character
      • Background processing
      • How to setup different FROM address for different Notifications
      • Custom Post Type support
      • Disable upselling
      • How to send HTML Emails
  • πŸ”§Developer
    • General
      • Plugin loading chain
      • Runtime
      • Extension possibilities
      • Creating an extension
      • Customizations
      • Bundling Notification plugin
      • White label mode
    • Notifications
      • Suppressing the Notification
      • JSON synchronization
      • Programmatic Notifications
    • Triggers
      • List of all default Triggers
      • Custom Trigger
      • Enable support for non-public Custom Post Type
      • Adding Merge Tags to existing Triggers
    • Carriers
      • Custom Carrier
      • Adding custom fields to Carrier form
      • Suppressing the Carrier
    • Recipients
      • Custom Recipient
    • Snippets
      • General
        • Automatic Trigger testing
        • Allow other roles to edit Notifications
        • Programmatic Notification with manual Trigger
        • Background Processing filter
      • Triggers
        • Post
        • User
      • Integations
        • WP All Import
        • MemberPress
  • 🧩Extensions
    • Installation
    • Planned extensions
    • 3rd Party Extensions
    • Custom Fields
      • v2.2
      • v1.4
      • v1.3
    • Conditionals
    • Email Attachments
    • Push
    • Scheduled Triggers
    • Slack
    • Twilio
    • Webhooks
Powered by GitBook
On this page
  • Regular meta
  • Advanced Custom Fields meta
  • BuddyPress XProfile
  • Output modifiers
  • Access array keys
  • Pipelines
  • Value formatting
  • Examples
  • Limitations

Was this helpful?

  1. Extensions

Custom Fields

Documentation for version 3 or later

Previous3rd Party ExtensionsNextv2.2

Last updated 6 months ago

Was this helpful?

Regular meta

The Custom Fields extension supports meta of three object types:

  • Posts

  • Users

  • Comments

Here are the examples with equivalents in get_****_meta()

{postmeta {post_ID} metakey}
// equivalent of:
// get_post_meta( $post_id, $metakey, true );
{usermeta {user_ID} metakey}
// equivalent of:
// get_user_meta( $user_id, $metakey, true );
{commentmeta {comment_ID} metakey}
// equivalent of:
// get_comment_meta( $comment_id, $metakey, true );

Note that {post_ID} or {user_ID} or {comment_ID} part is the object ID which can be static (like just 365783) or can be a merge tag. If you are using merge tags for this part, like in the examples, please make sure you can see this merge tag in the sidebar. So if you choose the Book updated trigger, the {post_ID} will become {book_ID}.

Advanced Custom Fields meta

Any ACF field value can be retrieved with the regular meta merge tags, but sometimes you'd want to let ACF format the data for you.

Very similar to regular meta you can use it like this:

{acf {post_ID} my_field_slug}
{acf comment_{comment_ID} fieldname}
{acf user_{user_ID} fieldname}
{acf term_{term_ID} fieldname}

Which is an equivalent of:

get_field( $fieldname, $item_id );

You can access the first-level array key as well

Giving an example, you can have a field of type User and return format of User array. Your meta will look like this:

Array
(
    [ID] => 1
    [user_firstname] => Panda
    [user_lastname] => Bear
    [nickname] => admin
    [user_nicename] => admin
    [display_name] => Panda Bear
    [user_email] => admin@example.com
    [user_url] => 
    [user_registered] => 2019-03-14 10:46:17
    [user_description] => 
    [user_avatar] => <img alt='' src='http://2.gravatar.com/avatar/21c9a0124feee215cb7c5759f7e6670b?s=96&#038;d=mm&#038;r=g' srcset='http://2.gravatar.com/avatar/21c9a0124feee215cb7c5759f7e6670b?s=192&#038;d=mm&#038;r=g 2x' class='avatar avatar-96 photo' height='96' width='96' />
)

To access the user_email key, you just need to do it like this:

{acf {post_ID} user_field:user_email}

BuddyPress XProfile

BuddyPress saves XProfile fields outside the user meta database tables, so it cannot be downloaded with acf or usermeta Merge Tags.

Instead, there's another type of xprofile Merge Tag, see the below examples.

Using nice field name

{xprofile {user_ID} Field Nice Name}

Using field ID

{xprofile {user_ID} 123}

Output modifiers

Access array keys

Getting the meta often means you need to work with arrays. Deeper levels can be easily accessed with : character.

Let's consider an example, where you have this array in your meta:

Array
(
    [date] => 2019-03-14 10:46:17
    [accepted] => 1
    [email] => 'user@example.com'
)

To access the email key you just need to pass the array key after the colon:

{postmeta {post_ID} metakey:email}

This will work with any type of meta.

Giving the ACF example, you can have a field of type User and return format of User array. Your meta will look like this:

Array
(
    [ID] => 1
    [user_firstname] => Panda
    [user_lastname] => Bear
    [nickname] => admin
    [user_nicename] => admin
    [display_name] => Panda Bear
    [user_email] => admin@example.com
    [user_url] => 
    [user_registered] => 2019-03-14 10:46:17
    [user_description] => 
    [user_avatar] => <img alt='' src='http://2.gravatar.com/avatar/21c9a0124feee215cb7c5759f7e6670b?s=96&#038;d=mm&#038;r=g' srcset='http://2.gravatar.com/avatar/21c9a0124feee215cb7c5759f7e6670b?s=192&#038;d=mm&#038;r=g 2x' class='avatar avatar-96 photo' height='96' width='96' />
)

To access the user_email key, you just need to do it like this:

{acf {post_ID} user_field:user_email}

Multidimensional arrays

But what in case you have a multidimensional array like this?

Array
(
    [user] => Array
    (
        [user_firstname] => Panda
        [user_lastname] => Bear
        [user_email] => admin@example.com
    )
)

Easy! Just pass the nested keys after another colon:

{... user_field:user:user_email}

Same story with numeric arrays:

Array
(
    [0] => Array
    (
        [user_firstname] => Panda
        [user_lastname] => Bear
        [user_email] => admin@example.com
    )
)
{... user_field:0:user_email}

Pipelines

Sometimes the value in meta is not exactly in a form you'd like. The most common scenario is having a post or user ID saved in the meta while you want to display a post_title or display_name.

Each pipe is processing the value and manipulate its representation. You can think about it like this:

Initial value -> replace -> reshape -> replace -> format

So the initial value of User ID can be replaced with a whole User object and this object can be formatted as JSON.

All supported pipelines:

Objects

Manipulators

Formatters

post

|post

postmeta

Gets the post meta.

|postmeta,$key,$single

$single will evaluate to boolean, so you can write any of: on, true, 1, yes, etc.

term

|term

termmeta

Gets the term meta.

|termmeta,$key,$single

$single will evaluate to boolean, so you can write any of: on, true, 1, yes, etc.

user

|user

usermeta

Gets the user meta.

|usermeta,$key,$single

$single will evaluate to boolean, so you can write any of: on, true, 1, yes, etc.

pluck

Plucks the values from the collection

|pluck,$key

Plucking the name key from this array:

Array
(
    [0] => Array
    (
        [name] => John Doe
    )
    [1] => Array
    (
        [name] => Jane Doe
    )
)

Will result with:

Array
(
    [0] => John Doe
    [1] => Jane Doe
)

join

Joins the array values into a comma-separated string.

|join

Joining an array:

Array
(
    [0] => John Doe
    [1] => Jane Doe
)

Will result with:

John Doe, Jane Doe

first

Gets the first element of an array.

|first

Getting the first element of an array:

Array
(
    [0] => John Doe
    [1] => Jane Doe
)

Will result with:

John Doe

last

Gets the last element of an array.

|last

Getting the last element of an array:

Array
(
    [0] => John Doe
    [1] => Jane Doe
)

Will result with:

Jane Doe

bool

Formats the boolean value in the desired way.

|bool,$true,$false
  • $true String to return when the value is evaluated to true

  • $false String to return when the value is evaluated to false

Example:

|bool,Active and ready to go,Disabled

json

Formats the value as json.

|json

Value formatting

String values are always displayed as literal strings. No HTML is escaped.

If the returned value is an array with a single item, it's automatically unwrapped and the first item is returned.

Array values are represented with print_r() function and wrapped with <pre> tags. Example:

Array
(
    [0] => Array
    (
        [name] => John Doe
    )
    [1] => Array
    (
        [name] => Jane Doe
    )
)

Boolean values are represented as Yes or No by default.

You can change the format by using the formatting pipes, like bool, join, or json.

Examples

Post has a related_post field (stored post ID) where another related post can be selected. The related post has a field where owner can be selected and this returns the user ID. To get this user email:

{postmeta {post_ID} related_post|postmeta,owner,true|user:user_email}

Explanation:

  • {postmeta {post_ID} related_post - gets the initial value of the related post, post ID is retrieved

  • |postmeta,owner,true - related post ID is used to get the meta key owner and true means the single value should be returned. We get the User ID.

  • |user:user_email - user ID is used to get the whole user representation. We access the user_email array key to get the email

Limitations

The plugin cannot handle iterators. Ie. if you want to map an array of users. In other words, it's not possible to work on the collections. The subsequent pipes are meant to reduce the data to a single value.

Pipes can be mixed together and each pipe can be used with the array accessors. They work with ACF and regular meta Merge Tags. .

Gets the as an array.

$key and $single arguments are optional. If you omit the $key argument all the post meta is retrieved. This is an equivalent of .

Gets the as an array.

$key and $single arguments are optional. If you omit the $key argument all the term meta is retrieved. This is an equivalent of .

Get the as an array.

$key and $single arguments are optional. If you omit the $key argument all the user meta is retrieved. This is an equivalent of .

$key argument is required. This is an equivalent of .

🧩
Download this extension
post object
get_post_meta function
term object
get_term_meta function
user object
get_term_meta function
wp_list_pluck function
See the example
post
first
bool
postmeta
last
join
term
pluck
json
termmeta
user
usermeta