You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One of our favorite, simple and intuitive features is the ability to update metaboxes dynamically whilst editing a post. For example, metaboxes will hide or show depending on their location rules when changing the post template, format, parent and other post attributes.
To do this, we use JS to detect "changes" to the post attributes. Once a change is detected, we send an AJAX request with the current "post" information and use the returned JSON to hide, show or update the metaboxes. We also update the "Show on Screen" checkbox elements to match the visible metaboxes.
Issues
Existing jQuery event listeners are not compatible with Gutenberg
Questions
How do we listen for changes to the following post attributes?
page_template
page_parent
post_format
post_terms
How do we get these values on initial page load?
How do we get these values on change?
How can we hide and show metaboxes? Is CSS ok for this?
How can we update the "Show on Screen" check boxes to match the visible metaboxes?
The text was updated successfully, but these errors were encountered:
How do we listen for changes to the following post attributes?
page_template
page_parent
post_format
post_terms
If we have a React component then we can make it update when there are changes by wrapping it with withSelect(). Otherwise, we'll need to do this manually using subscribe(). I suspect that ACF will need to use the latter approach as it's built using jQuery.
letpageTemplate;wp.data.subscribe(()=>{constnewPageTemplate=wp.data.select('core/editor').getEditedPostAttribute('template');if(pageTemplate!==newPageTemplate){console.log('Page template has changed!');pageTemplate=newPageTemplate;}});
Description
One of our favorite, simple and intuitive features is the ability to update metaboxes dynamically whilst editing a post. For example, metaboxes will hide or show depending on their location rules when changing the post template, format, parent and other post attributes.
To do this, we use JS to detect "changes" to the post attributes. Once a change is detected, we send an AJAX request with the current "post" information and use the returned JSON to hide, show or update the metaboxes. We also update the "Show on Screen" checkbox elements to match the visible metaboxes.
Issues
Questions
page_template
page_parent
post_format
post_terms
The text was updated successfully, but these errors were encountered: