Support Forum » User Profile

Forum Replies Created

Viewing 3 posts - 31 through 33 (of 33 total)
  • Author
    Posts
  • in reply to: rwmb_meta_boxes filter #5062
    woorisewoorise
    Participant

    The current is the one that is defined in the rwmb_meta_boxes filter: 'post_types' => 'testtype'

    I need to load the $content variable only on the testtype and not on the default post type.

    in reply to: rwmb_meta_boxes filter #5046
    woorisewoorise
    Participant

    I know that is working fine. My issue is that I am getting an "Undefined variable: content" notice by Query monitor on WordPress posts.

    My question is if there is any recommended way to make it run only on current custom post type? For example it also runs on post’s edit screen that's why I am getting the PHP notice. I am working on a multisite installation and the code is placed in a Plugin.

    Thank you.

    in reply to: rwmb_meta_boxes filter #4988
    woorisewoorise
    Participant

    The code is something like this:

    add_filter( 'rwmb_meta_boxes', 'test' );
    function test( $meta_boxes ) {
    	
    	// Get current post ID
    	$post_id = false;
    	if ( isset( $_GET['post'] ) ) {
    		$post_id = intval( $_GET['post'] );
    	}
    	elseif ( isset( $_POST['post_ID'] ) ) {
    		$post_id = intval( $_POST['post_ID'] );
    	}
    	
        if ( get_post_status( $post_id ) != 'publish' ) {
        	$content = 'Not Published';
        } else {
        	$content = 'Published';
        }
        
        $meta_boxes[] = array(
            'title'      => esc_html__( 'Test', 'test' ),
    		'post_types' => 'testtype',
    		'context'    => 'side',
    		'priority'   => 'low',
            'fields'     => array(
    			array(
    				'id'   => "_test",
    				'type' => 'custom_html',
    				'std'  => $content,
    			),
    		)
    	);
    	
    	return $meta_boxes;
    }
Viewing 3 posts - 31 through 33 (of 33 total)