Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress:致命错误:未捕获ArgumentCounter错误:函数posts_custom_columns()的参数太少,传入1个_Php_Wordpress - Fatal编程技术网

Php Wordpress:致命错误:未捕获ArgumentCounter错误:函数posts_custom_columns()的参数太少,传入1个

Php Wordpress:致命错误:未捕获ArgumentCounter错误:函数posts_custom_columns()的参数太少,传入1个,php,wordpress,Php,Wordpress,在wordpress中获取以下错误 (致命错误:Uncaught ArgumentCounter错误:函数posts\u custom\u columns()的参数太少,传入1个) 在管理员列表中启用特色图像时。下面是我在functions.php中添加的代码 add_filter('manage_posts_columns', 'posts_columns'); add_action('manage_posts_custom_column', 'posts_custom_columns');

在wordpress中获取以下错误

(致命错误:Uncaught ArgumentCounter错误:函数posts\u custom\u columns()的参数太少,传入1个)

在管理员列表中启用特色图像时。下面是我在functions.php中添加的代码

add_filter('manage_posts_columns', 'posts_columns');
add_action('manage_posts_custom_column', 'posts_custom_columns');
    function posts_columns($defaults){
    $defaults['wdm_post_thumbs'] = __('Featured Image'); //name of the column
    return $defaults;
}
function posts_custom_columns($column_name, $id){
        if($column_name === 'wdm_post_thumbs'){
        echo the_post_thumbnail(array(75,75)); //size of the thumbnail 
    }
}
删除此选项时没有错误。我需要知道它出了什么问题?

试着换一下

add_action('manage_posts_custom_column', 'posts_custom_columns');


如果您查看文档,您会发现它需要两个参数。(注意,第二个通常表示为
$post\u id

现在,如果您查看文档,您将看到它包含4个参数,第三个是
优先级
,第四个是发送到函数的参数数。由于传递的代码多于默认值
1
,因此需要将代码更新为:

add_action( 'manage_posts_custom_column', 'posts_custom_columns', 10, 2 );
因此,以下是我要做的事情,以改进它:

add_filter( 'manage_posts_columns', 'posts_columns' );
function posts_columns( $defaults ){
    $defaults['wdm_post_thumbs'] = __('Featured Image'); //name of the column
    return $defaults;
}

add_action( 'manage_posts_custom_column', 'posts_custom_columns', 10, 2 );
function posts_custom_columns( $column_name, $post_id ){
    if( $column_name === 'wdm_post_thumbs' ){
        echo the_post_thumbnail( array(75,75) ); //size of the thumbnail 
    }
}
请注意,如果您没有特别使用
$post\u id
参数,则可以将其从函数声明中省略:

add_action( 'manage_posts_custom_column', 'posts_custom_columns' );
function posts_custom_columns( $column_name ){
    if( $column_name === 'wdm_post_thumbs' ){
        echo the_post_thumbnail( array(75,75) ); //size of the thumbnail 
    }
}

最后一个注释是,你可能想重命名你的函数,因为<代码> PtsSuCuthuxStudio在命名冲突中已经成熟了,没有命名空间或者在一个类中。

谢谢你的好解释。你能告诉我这个问题有什么问题吗?
add_action( 'manage_posts_custom_column', 'posts_custom_columns' );
function posts_custom_columns( $column_name ){
    if( $column_name === 'wdm_post_thumbs' ){
        echo the_post_thumbnail( array(75,75) ); //size of the thumbnail 
    }
}