Post Meta

[su_meta key="mood" post_id="1"]

Table of contents

  1. Description
  2. Options
  3. Unsafe Feature

Description

This shortcode allows you to display custom field values.

Options

Option namePossible valuesDefault value
key
Meta key name
Any text value– none –
default
This text will be shown if data is not found
Any text value– none –
before
This content will be shown before the value
Any text value– none –
after
This content will be shown after the value
Any text value– none –
post_id
You can specify custom post ID. Leave this field empty to use an ID of the current post. Current post ID may not work in Live Preview mode
Any text value– none –
filter
You can apply custom filter to the retrieved value. Enter here function name. Your function must accept one argument and return modified value. Name of your function must include word filter. The following example code could be added to the end of the functions.php file of your theme:
function my_custom_filter( $value ) {return 'Value is: ' . $value;}
Any text value– none –

Unsafe Feature

Starting with plugin version 7.0.0, the [su_meta] shortcode is considered an Unsafe Feature. This means that the shortcode will be automatically disabled if your site has at least one user with a role lower than administrator (e.g. Contributor). Learn more about unsafe features.

However, you can still use the shortcode.

The first option is to enable Unsafe features by navigating to Dashboard > Shortcodes > Settings > Advanced settings. It is strongly discouraged if you have non-administrator users on your site (ex. Contributors), as they may use the shortcode to access sensitive information stored in post metadata.

The second method is to whitelist the specific meta fields. You can use the su/shortcode/meta/allowed_keys filter to do this. Put the code below to the end of the functions.php file of the active theme and add your meta field names.

add_filter('su/shortcode/meta/allowed_keys', function($allowed_keys) {
	$allowed_keys[] = 'mood';
	$allowed_keys[] = '_sku';

	return $allowed_keys;
});

The code above will allow you to use the following shortcodes even while the Unsafe features option is disabled:

[su_meta key="mood"]
[su_meta key="_sku"]
Helpful?
🤝 Thank you!