Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.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 验证元框中输入数组的问题_Php_Wordpress Theming_Wordpress - Fatal编程技术网

Php 验证元框中输入数组的问题

Php 验证元框中输入数组的问题,php,wordpress-theming,wordpress,Php,Wordpress Theming,Wordpress,我试图验证不同帖子的一组数据输入 $post_types=数组('movieCPT','bookCPT','paperCPT') 到目前为止,我有一个功能,可以分别为每个选项正确工作,如下所示 function save_options() { global $post; if (!isset($_POST['source']) || $post->post_type != 'movieCPT') { return $post; }

我试图验证不同帖子的一组数据输入

$post_types=数组('movieCPT','bookCPT','paperCPT')

到目前为止,我有一个功能,可以分别为每个选项正确工作,如下所示

function save_options()
{
    global $post;
      if (!isset($_POST['source']) || $post->post_type != 'movieCPT')
    {
        return $post;
    }
    update_post_meta($post->ID, "source", $_POST['source']);

}
现在,您可以让我知道如何为数组
$post\u types
而不是中的
movieCPT
传递对象吗

如果(!isset($_POST['source'])| |$POST->POST\u type!='movieCPT')

谢谢

更新

function save_options()
{
 $post_types = array ( 'movieCPT', 'bookCPT', 'paperCPT' );
    global $post;
   $cpt =   $post->post_type;

    if ((!isset($_POST['source'])) || (! in_array( $cpt, $post_types )))
    {
        return $post;
    }
    update_post_meta($post->ID, "source", $_POST['source']);

}

您想检查
$post->post\u type
是否不在
$post\u types
内?您好,是的,在这种情况下,post中没有更新您的更新已经可以了,我想,只需使用
in\u array()
。事实上,这就是我要说的。我也试着使用
!在_array()
函数中,该函数不起作用,请查看此函数的更新您的意思是没有