last day (14 days later) » 

6:22 AM
0
Q: Issue on Validating An array of Inputs in Meta Box

SuffiiI am trying to validate a group of data input for different posts as $post_types = array ( 'movieCPT', 'bookCPT', 'paperCPT' ); 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...

 
you want to check whether $post->post_type is not inside $post_types?
 
Hi Ghost yeah exactly, which in that case there is no update in the post
 
your update is already okay i guess, just use in_array(). actually thats what i was going to asnwer
 
I also tried to use the !in_array() function which didn't work please take a look at update for this
you mean without ! ?
 
nope, your answer i'll implement it just like that not in array => !in_array(): just make sure there are no extra spaces on the string $post->type. also check if they share the same upper/lowercase
 
6:23 AM
I removed the extra space but still same!
 
what i mean is the extra spaces of the needle "$post->type"
for example: "movieCPT " != "movieCPT". (the first one has a leading space)
 
well here is what I have now: 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']);

}
yeah but I didnt find any space before or after the array element!
wait wait! I think I am doing some thing wrong here!
Can you please let me know if I am doing correct operator || here?
shouldn't I use the && instead?
 
thats odd indeed, that should work fine.
that depends on your intent
 
wow it works with &&!
 
if you are checking if for both
for example:
if your checking if the source is undefined AND! its not inside the array., then yes you should use &&
but if you're checking for either one of them the use OR
oh okay, you got it working
glad it went your way
 
6:35 AM
Thanks Ghost, it was great help
 
sure man no prob
 

last day (14 days later) »