Hi Thowe,
Are you testing this while logged in?
Hi caimin,
thanks, that was the mistake. But, when I now fill out the required field and then klick submit. The error-message still appears?
Just to check, the required field is definitely called user_name and not username? That’s caught me out a few times.
if you wanted to make categories required; you can add this in your snippet above
$categories = $EM_Event->categories->categories;
if (!is_user_logged_in() && empty($categories) ){
$EM_Event->add_error('please choose categories...');
$result = false;
}
Hi Guys,
thanks a lot for your answers. But, both codes are not working for me.
When I’m using the first code in the theme functions.php, the error message appears, so to this point, it works. But when I fill out the attribute, then the error still appears after clicking on the submission button. I’m sure I spelled the attribute name the right way in the theme functions.php.
When I use the second code for categories in the theme functions.php the screen of my homepage stays white.
hmm, works for me; you can try to turn-on WP_DEBUG to check what is the error why it turns white or check your php logs.
Hi Angelo,
I turned on the debug mode. This are the error messages for the category code:
Notice: Undefined variable: EM_Event in /Applications/MAMP/htdocs/wp-content/themes/attitude/functions.php on line 155
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/wp-content/themes/attitude/functions.php on line 155
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/wp-content/themes/attitude/functions.php on line 155
and thats the Line 155:
$categories = $EM_Event->categories->categories;
using pastebin.com; can you share the entire function you added?
thanks
you paste the snippet incorrectly; try this revised code – http://pastebin.com/tJTSjL7d
Hi Angelo,
thanks a lot for the support. I pasted in the correct snippet. But know I got another error, although I filled out the required attribute:
Notice: Undefined index: Ansprechpartner: in /Applications/MAMP/htdocs/wp-content/themes/attitude/functions.php on line 156
And this is the code:
if (!is_user_logged_in() && $_REQUEST['Ansprechpartner:'] == ''){
hmm, just remove the block
if (!is_user_logged_in() && $_REQUEST['Ansprechpartner:'] == ''){
........
}
and then else {.....}
just used this snippet
$categories = $EM_Event->categories->categories;
if (!is_user_logged_in() && empty($categories) ){
$EM_Event->add_error('please choose categories...');
$result = false;
}
Hi Angelo,
but then only the categories are required. But I want both, attributes and categories.
Hiya,
Try this instead: http://pastebin.com/wRgHxHWB
Phil