{"id":49,"date":"2025-09-26T08:50:54","date_gmt":"2025-09-26T08:50:54","guid":{"rendered":"https:\/\/ska-blocks.com\/docs\/2025\/09\/26\/post-data-block\/"},"modified":"2025-09-27T10:03:14","modified_gmt":"2025-09-27T10:03:14","slug":"post-data-block","status":"publish","type":"post","link":"https:\/\/ska-blocks.com\/docs\/post-data-block\/","title":{"rendered":"Post data block"},"content":{"rendered":"\n<p class=\"lead\">The Post data block can render various data related to the current post.<\/p>\n\n\n\n<p><code>ska\/post-data<\/code> is an alternative to WordPress core blocks such as Title, Excerpt and Categories. The block aims to produce cleaner markup than the aforementioned as well as support more customization options, such as using a different tag name and adding custom HTML attributes.<\/p>\n\n\n\n<div role=\"figure\" class=\"inline-block ring ring-site-border wp-block-ska-image image\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ska-blocks.com\/docs\/wp-content\/uploads\/sites\/3\/2025\/09\/image-21.png\" alt=\"Post data block type options - Title, Archive title, Excerpt, Meta, Terms, Price, Time to read\" width=\"270\" height=\"184\"\/><\/div>\n\n\n\n<p>The Post data appearance controls allow to truncate the value to a certain max length.<\/p>\n\n\n\n<div role=\"figure\" class=\"inline-block wp-block-ska-image image\"><img decoding=\"async\" src=\"https:\/\/ska-blocks.com\/docs\/wp-content\/uploads\/sites\/3\/2024\/03\/image-29.png\" alt=\"Post data block appearance options - max length, prefix, suffix\"\/><\/div>\n\n\n\n<p>When in <strong>Terms<\/strong> mode, the max length determines how many terms (Categories, Tags) are displayed.<\/p>\n\n\n\n<p>The following filter can be used to modify the output of this block:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Filters<\/h2>\n\n\n\n<p>When using the <strong>Post data<\/strong> block with type <strong>Meta<\/strong> you can alter the meta value that it has fetched with the following filter (this works when the meta had a truthy value):<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><header><span class=\"title\">Modify the value of post data block Meta value<\/span><span class=\"label language-php\">PHP<\/span><\/header><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">\/**\n * @param mixed $meta_value Truthy and scalar meta value.\n * @param string $meta_key Meta key that the value is from.\n * @return string Value to render.\n *\/\nadd_filter('ska_blocks_render_post_meta', function($meta_value, $meta_key) {\n\treturn $meta_value;\n}, 10, 2);<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n\n\n\n<p>Alternatively, you can provide a value to early and not hit the <code>get_post_meta<\/code> call at all, which allows to use this block to provide any sort of output, not actual post meta:<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><header><span class=\"title\">Sideload the value of Post data block Meta value<\/span><span class=\"label language-php\">PHP<\/span><\/header><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">\/**\n * @param string $meta_value Empty string.\n * @param string $meta_key Meta key that the value is from.\n * @return string Value to render instead of retrieving post meta.\n *\/\nadd_filter('ska_blocks_pre_render_post_meta', function($meta_value, $meta_key) {\n\treturn $meta_value;\n}, 10, 2);<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n\n\n\n<p>The final value that is rendered in any case can be modified with the following filter:<\/p>\n\n\n\n<div class=\"wp-block-ska-code not-prose ska-preset--ska-theme--code\"><header><span class=\"title\">Modify the final value of Post data block<\/span><span class=\"label language-php\">PHP<\/span><\/header><div class=\"content\"><pre class=\"code php language-php\"><code class=\"language-php\">\/**\n * @param array $attributes Block attributes.\n * @param WP_Block $block Block instance.\n * @return string\n *\/\nadd_filter('ska_blocks_render_post_data', function($output, $attributes, $block) {\n\treturn $output;\n}, 10, 3);<\/code><\/pre><button :class=\"{error: state === &apos;error&apos;, success: state === &apos;success&apos;}\" x-data=\"{state:&apos;&apos;}\" x-on:click=\"navigator.clipboard ? (navigator.clipboard.writeText($el.previousElementSibling.innerText), $el.innerText = `Copied!`, state = &apos;success&apos;) : ($el.innerText = `Can&amp;#039;t copy`, state = &apos;error&apos;)\" class=\"copy\" type=\"button\">Copy<\/button><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The Post data block can render various data related to the current post. ska\/post-data is an alternative to WordPress core blocks such as Title, Excerpt and Categories. The block aims to produce cleaner markup than the aforementioned as well as support more customization options, such as using a different tag name and adding custom HTML&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[4],"class_list":["post-49","post","type-post","status-publish","format-standard","hentry","category-ska-theme","tag-blocks"],"_links":{"self":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/49","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/comments?post=49"}],"version-history":[{"count":2,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/49\/revisions"}],"predecessor-version":[{"id":358,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/posts\/49\/revisions\/358"}],"wp:attachment":[{"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/media?parent=49"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/categories?post=49"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ska-blocks.com\/docs\/wp-json\/wp\/v2\/tags?post=49"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}