Skip to content
Advertisement

Problem with WordPress call_user_func_array() and add_action

I am programming a WordPress plugin, but I had trouble creating WordPress metadata.

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'wp_api_savee_prices_metabox' not found or invalid function name in C:laragonwwwwordpresswp-includesclass-wp-hook.php on line ۳۰۵

Please guide me. Thanks

My metabox file code :

<?php


function wp_api_add_price_metabox($post_type, $post)
{
    add_meta_box(
        'wpapimetabox',
        'قیمت مطلب',
        'wp_api_price_metabox_handler',
        'post',
        'normal',
        'default'
    );
    function wp_api_price_metabox_handler($post)
    {
        
        ?>
        <label for="txt1">قیمت را وارد کنید:</label>
        <input type="text" id="txt1" name="wp_api_post_prices">
        <?php
        
    }
    function wp_api_savee_prices_metabox($post_id)
    {
        if(isset($_POST['wp_api_post_prices']))
        {
            update_post_meta($post_id,'wp_api_prices',$_POST['wp_api_post_prices']);
        }
    }
}
add_action('add_meta_boxes', 'wp_api_add_price_metabox', 10, 2);
add_action('save_post','wp_api_savee_prices_metabox');

Note: I am creating a metadata for posts.

Advertisement

Answer

You have added wp_api_savee_prices_metabox function inside wp_api_add_price_metabox Try the below code.

function wp_api_add_price_metabox($post_type, $post){
    add_meta_box(
        'wpapimetabox',
        'قیمت مطلب',
        'wp_api_price_metabox_handler',
        'post',
        'normal',
        'default'
    );
}
add_action('add_meta_boxes', 'wp_api_add_price_metabox', 10, 2);

function wp_api_price_metabox_handler($post){
    
    ?>
    <label for="txt1">قیمت را وارد کنید:</label>
    <input type="text" id="txt1" name="wp_api_post_prices">
    <?php
    
}

function wp_api_savee_prices_metabox($post_id){
    if(isset($_POST['wp_api_post_prices']))
    {
        update_post_meta($post_id,'wp_api_prices',$_POST['wp_api_post_prices']);
    }
}
add_action('save_post','wp_api_savee_prices_metabox');
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement