In block themes patterns won’t have access to context such as id it seems:
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-patterns
One has to create a custom block to get post id and use useSelect hook to get post Id like so:
import { useSelect } from "@wordpress/data";
…
inside Edit block function:
const postId = useSelect(select => select('core/editor').getCurrentPostId());
then, postId can be used inside edit function and if it has to be used in save function, useEffect should be used inside edit to store id to attribute like so:
useEffect(() => {
if (postId) {
setAttributes({postId})
}, [postId]);
Provided you have defined postId attribute in block.json, you can get and use that attribute in save function or render_callback.
Related Posts:
- WordPress Full Site Editing: How can I access my posts listing page?
- block theme FSE – save changes to the theme?
- How to set the background color of a template part (Header/Footer) in Twenty Twentythree?
- How to move the customizations done in the Editor to my child theme?
- Block Theme Template parts – Why saving a part updates the other ones?
- Full Site Editing (FSE) – How do I display no results with wp:query?
- How can I disable fontSizes of the Paragraph block inside the Quote block with theme.json?
- In Full Site Editing, how do I get the templates I created to appear in the site editor when populating a new page?
- Custom Link Block with own background color
- Default RichText Editor custom block fails validation
- Position tab missing in the Block Theme Editor
- Set a default overlay color for the Core Cover block in theme.json
- Extending the Query Loop block
- Query Loop block display multiple post types
- Possible to use @wordpress/create-block with multiple blocks?
- What is the advantage of ‘register_block_type’ (the PHP function) when creating custom blocks?
- The Block Editor: Disable “Color settings” in the specific block
- Serialize custom block with InnerBlock
- Gutenberg Range Control default from meta value
- Why is the new Gutenberg editor so narrow, and how to make it wider?
- Why does the custom HTML block not preserve the HTML characters?
- Can’t get dynamic Gutenberg block to render on the frontend
- Gutenberg change/remove “Write your story” placeholder in custom blocks
- How do I listen for a change in an innerBlock child?
- How to enable Gutenberg Block Editor on taxonomy term pages?
- How to make 2/3 width column in Gutenberg
- Change default colors in paragraph block settings
- Gutenberg Reusable Block of WordPress
- Add custom attributes to link in Gutenberg
- How do I add a Gutenberg editor to a custom options page
- how define elements type in attributes type array of gutenberg blocks
- Convert GMT time to local time in Gutenberg Block Editor
- Restrict heading level in Gutenberg block `core/heading`
- How do I disable or hide the Layout block setting in the Group block
- I cant see Block Editor with v5.7
- How to update block attribute after format is applied?
- How to add a class to the link of the default Gutenberg Button block?
- How to identify what templates are being loaded in a block-based theme [closed]
- Check if current page is using blocks (Gutenberg) or is legacy
- Add support for ‘alignnone’ to Gutenberg block align controls?
- Converting a theme to Gutenberg but some styles are missing in the front end [closed]
- How to disable align-wide for specified blocks in Gutenberg
- Deprecated function not working in Gutenberg
- WordPress npm run build and start only outputs wp-scripts start but does nothing
- Gutenberg get index of gutenberg innerblock
- Custom Endpoint API based on attribute gutenberg block
- Gutenberg – Remove add block button
- how can default_content filter tell if content will load in block editor or classic editor?
- Gutenberg programmatically move block to position
- Gutenberg block – remove setting for core/file
- Gutenberg JavaScript error
- Gutenberg selecting child blocks directly from appender
- Image not aligning with text
- Modify src attribute on image block
- Two text color palettes are appearing in Gutenberg
- WordPress Gutenberg – Sidebar get posts list based on selected category
- Gutenberg button removed on save if its empty
- Gutenberg build error: You may need an appropriate loader to handle this file type SCSS
- Gutenberg: How to constrict floated table blocks to 1000px width in the front-end, when align wide & full are being used?
- Table block – Wrap table
- ResizableBox component is not selectable in block editor
- Whitelist a single SVG for use in post_content
- Gutenberg block previews suddenly not working
- How to do store, retrieve and write attributes in the registerFormatType method in Guttenberg?
- How can I create more advanced layouts in Gutenberg block editor?
- How to replace the Gutenberg default block with a custom block?
- how to disable a button added by a plugin in gutenberg toolbar?
- Images are not shown in the post editor
- Updating failed message when a wp_insert_post function is hooked to save_post hook
- Get post ancestors in the Block Editor
- How to disable blocks in Gutenberg editor for specific post type
- Possible to make the link autocompleter prioritize Tags before Posts?
- Prevent FormTokenField component to accept random entries
- Unable to see the attributes for the custom block created
- How to register multiple blocks
- How to edit post meta by post ID in Gutenberg
- How do I change bullet on categories block?
- Add a class to img of core/cover block
- Hide title block on edit screen in Gutenberg
- Where is getSite selector defined?
- How properly use social link block in template part
- How to self host fonts and have them show up in all the Full Site Block Editor Typography options, including global styling
- How do I have two RadioControls in my custom Gutenberg block?
- WordPress block editor template parts not saving
- Conditionally Load JS for Block Style
- Custom WP Blocks (register_block_type) in a Parent Theme
- How do I load styles into the block editor admin screen?
- Removing Default Panels From Gutenberg Document Setting Panel (sidebar)
- Disable block editor pre-publish sidebar for custom post type
- Not allowing my site to be embedded elsewhere via oEmbed
- I want to horizontally align items in multiple parallel columns under one column block
- Override base Gutenberg block default spacing in child theme’s theme.json
- Execute JavaScript code when your custom block is inserted
- Align block editor
- Saving a meta value as an object using useEntityProp
- wp:query not responding to new settings
- Embeds (YouTube, Spotify) Work Live but Won’t Load in Block Editor [closed]
- How can I get rid of extra line space in this poetry stanza
- set allowedBlocks to a specific variant
- Add custom settings to standard Gutenberg blocks