This topic contains 2 replies, has 2 voices, and was last updated by  searchpro 4 years, 8 months ago.

  • Creator
    Topic
  • #276

    searchpro
    Participant

    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' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #285

    Anh Tran
    Keymaster

    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.

    #288

    searchpro
    Participant

    Thank you, the new plugin files worked perfectly. I have also updated my code as suggested. Much cleaner. Great work!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Post Parent’ is closed to new replies.