{"id":33969,"date":"2019-03-04T10:33:49","date_gmt":"2019-03-04T10:33:49","guid":{"rendered":"http:\/\/getshortcodes.com\/?post_type=docs&#038;p=33969"},"modified":"2023-11-23T09:02:33","modified_gmt":"2023-11-23T09:02:33","slug":"post-meta","status":"publish","type":"docs","link":"https:\/\/getshortcodes.com\/docs\/post-meta\/","title":{"rendered":"Post Meta"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>&#091;su_meta key=\"mood\" post_id=\"1\"]<\/code><\/pre>\n\n\n<p class=\"h2\">Table of contents<\/p>\n\n<ol><li><a href=\"#description\">Description<\/a><\/li><li><a href=\"#options\">Options<\/a><\/li><li><a href=\"#unsafe-feature\">Unsafe Feature<\/a><\/li><\/ol><\/li><\/ol>\n\n\n<h2 class=\"wp-block-heading\" id=\"description\">Description<\/h2>\n\n\n\n<p>This shortcode allows you to display custom field values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"options\">Options<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><tbody><tr><th>Option name<\/th><th>Possible values<\/th><th>Default value<\/th><\/tr><tr><td><strong>key<\/strong><br>Meta key name<\/td><td>Any text value<\/td><td><em>\u2013 none \u2013<\/em><\/td><\/tr><tr><td><strong>default<\/strong><br>This text will be shown if data is not found<\/td><td>Any text value<\/td><td><em>\u2013 none \u2013<\/em><\/td><\/tr><tr><td><strong>before<\/strong><br>This content will be shown before the value<\/td><td>Any text value<\/td><td><em>\u2013 none \u2013<\/em><\/td><\/tr><tr><td><strong>after<\/strong><br>This content will be shown after the value<\/td><td>Any text value<\/td><td><em>\u2013 none \u2013<\/em><\/td><\/tr><tr><td><strong>post_id<\/strong><br>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<\/td><td>Any text value<\/td><td><em>\u2013 none \u2013<\/em><\/td><\/tr><tr><td><strong>filter<\/strong><br>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: <br><code>function my_custom_filter( $value ) {return 'Value is: ' . $value;}<\/code><\/td><td>Any text value<\/td><td><em>\u2013 none \u2013<\/em><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"unsafe-feature\">Unsafe Feature<\/h2>\n\n\n\n<p>Starting with plugin version 7.0.0, the  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). <a href=\"\/docs\/unsafe-features\/\">Learn more about unsafe features<\/a>.<\/p>\n\n\n\n<p>However, you can still use the shortcode.<\/p>\n\n\n\n<p>The first option is to enable <em>Unsafe features<\/em> by navigating to <em>Dashboard > Shortcodes > Settings > Advanced settings<\/em>. 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.<\/p>\n\n\n\n<p>The second method is to whitelist the specific meta fields. You can use the <code>su\/shortcode\/meta\/allowed_keys<\/code> filter to do this. Put the code below to the end of the <em>functions.php<\/em> file of the active theme and add your meta field names.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>add_filter('su\/shortcode\/meta\/allowed_keys', function($allowed_keys) {\n\t$allowed_keys&#091;] = 'mood';\n\t$allowed_keys&#091;] = '_sku';\n\n\treturn $allowed_keys;\n});<\/code><\/pre>\n\n\n\n<p>The code above will allow you to use the following shortcodes even while the Unsafe features option is disabled:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#091;su_meta key=\"mood\"]\n&#091;su_meta key=\"_sku\"]<\/code><\/pre>\n","protected":false},"featured_media":36689,"template":"","docs_category":[21],"class_list":["post-33969","docs","type-docs","status-publish","has-post-thumbnail","hentry","docs_category-shortcodes"],"_links":{"self":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs\/33969","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/types\/docs"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/media\/36689"}],"wp:attachment":[{"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/media?parent=33969"}],"wp:term":[{"taxonomy":"docs_category","embeddable":true,"href":"https:\/\/getshortcodes.com\/api\/wp\/v2\/docs_category?post=33969"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}