Support Forum
Support › Meta Box Include Exclude › Post Parent
I am having trouble getting the parent functionality to work with the include/exclude plugin.
I am working with normal "pages" (not posts). I assume since only pages have parent functionality out of the box with WP that this should be working fine.
The idea is to have the meta boxes included for all child pages of said parent.
Is this tested on the latest version of WordPress with the latest version of Meta Box? Here is my code below, please let me know if I am doing it wrong.
// CUSTOM METABOXES VIA META-BOX PLUGIN
$prefix = 'trf_';
global $meta_boxes;
$meta_boxes = array();
// Events
$meta_boxes[] = array(
'id' => 'events',
'title' => __( 'Event Details', 'rwmb' ),
'pages' => array( 'page' ),
// Register this meta box for posts matched below conditions
'include' => array(
'relation' => 'OR',
'parent' => array( 4899 ),
),
'fields' => array(
array(
'name' => __( 'Event Date', 'rwmb' ),
'id' => "{$prefix}event-date",
'type' => 'text',
),
array(
'name' => __( 'Event Time', 'rwmb' ),
'id' => "{$prefix}event-time",
'type' => 'text',
),
array(
'name' => __( 'Event Location', 'rwmb' ),
'id' => "{$prefix}event-location",
'type' => 'text',
),
)
);
/********************* META BOX REGISTERING ***********************/
function trf_register_meta_boxes()
{
// Make sure there's no errors when the plugin is deactivated or during upgrade
if ( !class_exists( 'RW_Meta_Box' ) )
return;
global $meta_boxes;
foreach ( $meta_boxes as $meta_box )
{
new RW_Meta_Box( $meta_box );
}
}
add_action( 'admin_init', 'trf_register_meta_boxes' );
Hi, thank you for reporting this. I've just checked your code above and found that it's a bug of the plugin. So I update it, please re-download the plugin (with the same link in your email or your profile page) and re-upload it to your host, overwrite old files.
By the way, I suggest updating the code to register meta boxes to the new style, like this:
<?php
add_filter( 'rwmb_meta_boxes', 'trf_meta_boxes' );
function trf_meta_boxes( $meta_boxes )
{
$prefix = 'trf_';
$meta_boxes[] = array(
'title' => __( 'Event Details', 'rwmb' ),
'pages' => array( 'page' ),
// Register this meta box for posts matched below conditions
'include' => array(
'parent' => array( 4899 ),
),
'fields' => array(
array(
'name' => __( 'Event Date', 'rwmb' ),
'id' => "{$prefix}event-date",
'type' => 'text',
),
array(
'name' => __( 'Event Time', 'rwmb' ),
'id' => "{$prefix}event-time",
'type' => 'text',
),
array(
'name' => __( 'Event Location', 'rwmb' ),
'id' => "{$prefix}event-location",
'type' => 'text',
),
)
);
return $meta_boxes;
}
Thanks.
Thank you, the new plugin files worked perfectly. I have also updated my code as suggested. Much cleaner. Great work!