Issue on Validating An array of Inputs in Meta Box

I am trying to validate a group of data input for different posts as

$post_types = array ( ‘movieCPT’, ‘bookCPT’, ‘paperCPT’ );

Read More

so far I have a function which work correct individually for each of the options as

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

}

now can you please let me know how to pass an object for array $post_types instead of movieCPT in

if (!isset($_POST[‘source’]) || $post->post_type != ‘movieCPT’)

Thanks

Update

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']);

}

Related posts

Leave a Reply