• Resolved Juan Pablo

    (@jupa8)


    Hello, I am trying to use the rwmb_show filter, seeing that it does not work, I have replicated the example that you have on the documentation page but it does not work either, it returns this error:

    Uncaught ArgumentCountError: Too few arguments to function {closure}(), 1 passed in /Users/jupa/Local Sites/wordpress/app/public/wp-includes/class-wp-hook.php on line 326 and exactly 2 expected in /Users/jupa/Local Sites/wordpress/app/public/wp-content/themes/naked/includes/custom-metaboxes.php:128 Stack trace: #0 /Users/jupa/Local Sites/wordpress/app/public/wp-includes/class-wp-hook.php(326): {closure}(true) #1 /Users/jupa/Local Sites/wordpress/app/public/wp-includes/plugin.php(205): WP_Hook->apply_filters(true, Array) #2 /Users/jupa/Local Sites/wordpress/app/public/wp-content/plugins/meta-box/inc/meta-box.php(75): apply_filters(‘rwmb_show_event…’, true, Array) #3 /Users/jupa/Local Sites/wordpress/app/public/wp-content/plugins/meta-box/inc/meta-box.php(57): RW_Meta_Box->is_shown() #4 /Users/jupa/Local Sites/wordpress/app/public/wp-content/plugins/meta-box/inc/meta-box-registry.php(19): RW_Meta_Box->__construct(Array) #5 /Users/jupa/Local Sites/wordpress/app/public/wp-content/plugins/meta-box/inc/core.php(32): RWMB_Meta_Box_Registry->make(Array) #6 /Users/jupa/Local Sites/wordpress/app/public/wp-includes/class-wp-hook.php(324): RWMB_Core->register_meta_boxes(”) #7 /Users/jupa/Local Sites/wordpress/app/public/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #8 /Users/jupa/Local Sites/wordpress/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #9 /Users/jupa/Local Sites/wordpress/app/public/wp-settings.php(695): do_action(‘init’) #10 /Users/jupa/Local Sites/wordpress/app/public/wp-config.php(112): require_once(‘/Users/jupa/Loc…’) #11 /Users/jupa/Local Sites/wordpress/app/public/wp-load.php(50): require_once(‘/Users/jupa/Loc…’) #12 /Users/jupa/Local Sites/wordpress/app/public/wp-admin/admin.php(34): require_once(‘/Users/jupa/Loc…’) #13 /Users/jupa/Local Sites/wordpress/app/public/wp-admin/post.php(12): require_once(‘/Users/jupa/Loc…’) #14 {main} thrown in /Users/jupa/Local Sites/wordpress/app/public/wp-content/themes/naked/includes/custom-metaboxes.php on line 128

    And this is my testing code

    add_filter( 'rwmb_meta_boxes', function ( $meta_boxes ) {
    $meta_boxes[] = [
    'title' => 'Event details',
    'id' => 'event-details',
    'post_types' => 'page',
    'fields' => [
    [
    'name' => 'Date and time',
    'id' => 'datetime',
    'type' => 'datetime',
    ],
    'Location',
    [
    'name' => 'Map',
    'id' => 'map',
    'type' => 'osm',
    'address_field' => 'location',
    ],
    ],
    ];
    return $meta_boxes;
    } );
    
    add_filter( 'rwmb_show_event-details', function( $show, $meta_box ) {
    $post_id = isset( $_GET['post'] ) ? $_GET['post'] : null;
    if ( $post_id === 123 ) {
    $show = false;
    }
    return $show;
    } );

    I need to show some custom fields only on the home page and I would like to limit them by page id.
    Thank you very much for any help you can give me.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi @jupa8

    The filter supports 2 parameters, and you’re using both of them as the parameters for the callback. To use more than 1 parameter, you need to specify the number of parameters in the add_filter, like this:

    add_filter( 'rwmb_show_event-details', 'your_callback_function', 10, 2 ); // 2 is the number of parameters.

    So, in this case, please rewrite your code as this:

    add_filter( 'rwmb_show_event-details', function( $show, $meta_box ) {
        $post_id = isset( $_GET['post'] ) ? $_GET['post'] : null;
        if ( $post_id === 123 ) {
            $show = false;
        }
        return $show;
    }, 10, 2 ); // THIS: you need to specify 2 as the number of parameters for the function.
    Thread Starter Juan Pablo

    (@jupa8)

    Hi, ThanKs Anh, I don’t know why the coMparison with === dont works on my code, I have to use ==

    This code works for me, thanks for help

    add_filter( 'rwmb_show_untitled', function( $show ) {
    	$post_id = isset( $_GET['post'] ) ? $_GET['post'] : null;
    	if ( $post_id == 601 ) {
    		$show = false;
    	}
    	return $show;
    } );
    • This reply was modified 5 months, 4 weeks ago by Juan Pablo.
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.