[su_post field="post_title" post_id=""]
This shortcode allows to display various post fields, including post title, post content, modified date etc.
Option name | Possible values | Default value |
---|---|---|
field Post data field name | ID (Post ID) post_author (Post author) post_date (Post date) post_date_gmt (Post date GMT) post_content (Post content (Raw)) the_content (Post content (Filtered)) post_title (Post title) post_excerpt (Post excerpt) post_status (Post status) comment_status (Comment status) ping_status (Ping status) post_name (Post name) post_modified (Post modified) post_modified_gmt (Post modified GMT) post_parent (Post parent) guid (GUID) menu_order (Menu order) post_type (Post type) post_mime_type (Post mime type) comment_count (Comment count) | post_title |
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. Post slug is also allowed. Leave this field empty to use ID of the current post. Current post ID may not work in Live Preview mode | Any text value | – none – |
post_type Post type of the post you want to display the data from | Post type slug(s) separated by comma(s) | post |
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. Example function: function my_custom_filter( $value ) {return 'Value is: ' . $value;} | Any text value | – none – |
Since version 5.12.8 the plugin only allows you to display a set of specific post fields (see the Options table above for the full list). Any fields that are not whitelisted will trigger the “field is not allowed” error.
This mechanism was introduced to improve the plugin security, since the shortcode can be used, for example, by a contributor user to access sensitive information about any post of the site.
The list of allowed fields can be extended with the su/config/post_fields
filter. To whitelist a specific field, add the code below to the end of the functions.php file of active theme. Please be careful, since the added field can be used by other writers on your site.
add_filter( 'su/config/post_fields', function( $fields ) {
// The field 'post_field' will be whitelisted
// and the 'Post Field' string will be used in the Insert Shortcode window
$fields['post_field'] = 'Post Field';
return $fields;
} );