Enabling to show private posts in parent dropdown / hierarchic CPT.
The the following code gets this done.
function show_private_posts_in_parent_dropdown( $args, $post ) {
$args['post_status'] = array( 'publish', 'private' );
return $args;
}
add_filter( 'page_attributes_dropdown_pages_args', 'show_private_posts_in_parent_dropdown', 10, 2 );
// also show private posts in the parent dropdown in quick edit
add_filter( 'quick_edit_dropdown_pages_args', 'show_private_posts_in_parent_dropdown', 10, 2 );
Getting Values from Parent Block.
on edit.js.
const parentBlock = useSelect(
(select) => {
const { getBlockParents, getBlock } = select("core/block-editor");
const parentClientIds = getBlockParents(clientId);
for (const parentClientId of parentClientIds) {
const parentBlock = getBlock(parentClientId);
if (parentBlock && parentBlock.name === "form-builder/form-builder") {
return parentBlock;
}
}
return null;
},
[clientId]
);
// Get the parent block's attributes
const parentAttributes = parentBlock ? parentBlock.attributes : {};
// Get the cpt_name attribute from the parent block
const cptName = parentAttributes.selectedCpt;
useEffect(() => {
console.log("Parent CPT Name:", cptName);
// Do something with the cpt_name attribute
}, [cptName]);