admin管理员组文章数量:1130349
I am trying to show different messages based on user's custom field data. 'Site-access' meta field can be 0 or 1 and I was able to retrieve it for logged in user using
the_field('site-access', wp_get_current_user());
Now I have to apply a comparison statement to this command based on retrieved data. Unfortunately it doesn't work within ELSE IF tags and I can't assign it to variable.
$access = the_field('site-access', wp_get_current_user());
if($access == "1"){
echo 'welcome';
}
else {
echo 'access denied';
}
Working code
$access = get_field('site-access', 'user_' . get_current_user_id());
$int = (int)$access;
echo $int;
if ($int == "1") {
echo "it's 1";
} else {
echo "it's not 1";
}
I am trying to show different messages based on user's custom field data. 'Site-access' meta field can be 0 or 1 and I was able to retrieve it for logged in user using
the_field('site-access', wp_get_current_user());
Now I have to apply a comparison statement to this command based on retrieved data. Unfortunately it doesn't work within ELSE IF tags and I can't assign it to variable.
$access = the_field('site-access', wp_get_current_user());
if($access == "1"){
echo 'welcome';
}
else {
echo 'access denied';
}
Working code
$access = get_field('site-access', 'user_' . get_current_user_id());
$int = (int)$access;
echo $int;
if ($int == "1") {
echo "it's 1";
} else {
echo "it's not 1";
}
Share
Improve this question
edited Nov 15, 2018 at 15:10
Johnny Dark
asked Nov 15, 2018 at 14:26
Johnny DarkJohnny Dark
52 bronze badges
1 Answer
Reset to default 1It could work like this; but you need to use get_field() instead of the_field(), since the latter displays the field instead of returning a value.
See https://www.advancedcustomfields/resources/the_field/ for more information.
I am trying to show different messages based on user's custom field data. 'Site-access' meta field can be 0 or 1 and I was able to retrieve it for logged in user using
the_field('site-access', wp_get_current_user());
Now I have to apply a comparison statement to this command based on retrieved data. Unfortunately it doesn't work within ELSE IF tags and I can't assign it to variable.
$access = the_field('site-access', wp_get_current_user());
if($access == "1"){
echo 'welcome';
}
else {
echo 'access denied';
}
Working code
$access = get_field('site-access', 'user_' . get_current_user_id());
$int = (int)$access;
echo $int;
if ($int == "1") {
echo "it's 1";
} else {
echo "it's not 1";
}
I am trying to show different messages based on user's custom field data. 'Site-access' meta field can be 0 or 1 and I was able to retrieve it for logged in user using
the_field('site-access', wp_get_current_user());
Now I have to apply a comparison statement to this command based on retrieved data. Unfortunately it doesn't work within ELSE IF tags and I can't assign it to variable.
$access = the_field('site-access', wp_get_current_user());
if($access == "1"){
echo 'welcome';
}
else {
echo 'access denied';
}
Working code
$access = get_field('site-access', 'user_' . get_current_user_id());
$int = (int)$access;
echo $int;
if ($int == "1") {
echo "it's 1";
} else {
echo "it's not 1";
}
Share
Improve this question
edited Nov 15, 2018 at 15:10
Johnny Dark
asked Nov 15, 2018 at 14:26
Johnny DarkJohnny Dark
52 bronze badges
1 Answer
Reset to default 1It could work like this; but you need to use get_field() instead of the_field(), since the latter displays the field instead of returning a value.
See https://www.advancedcustomfields/resources/the_field/ for more information.
本文标签: Wordpress PHP command and ELSE IF problem
版权声明:本文标题:Wordpress PHP command and ELSE IF problem 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749177626a2328065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论