admin管理员组文章数量:1130349
I am trying to create 2 raido buttons as a category custom field, and in function.php I do:
$feat = get_term_meta( $tag->term_id, '_feat', true );
<input name="feat" type="radio" value="0" <?php checked( '0' ); ?> />Si<br>
<input name="feat" type="radio" value="1" <?php checked( '1' ); ?> />No
And then I do
if ( isset( $_POST['feat'] ) )
update_term_meta( $_POST['tag_ID'], '_feat', $_POST['feat'] );
But I always get "No" as checked
I am trying to create 2 raido buttons as a category custom field, and in function.php I do:
$feat = get_term_meta( $tag->term_id, '_feat', true );
<input name="feat" type="radio" value="0" <?php checked( '0' ); ?> />Si<br>
<input name="feat" type="radio" value="1" <?php checked( '1' ); ?> />No
And then I do
if ( isset( $_POST['feat'] ) )
update_term_meta( $_POST['tag_ID'], '_feat', $_POST['feat'] );
But I always get "No" as checked
Share Improve this question asked Nov 23, 2018 at 12:12 rob.mrob.m 2072 silver badges9 bronze badges1 Answer
Reset to default 2The purpose of checked() is to output a checked="checked" attribute based on a current value. By using it the way you're using it there you're forcing Si to never be checked and No to always be checked.
So what you want to do is use both arguments of checked() to compare the value of the input to the current value:
<input name="feat" type="radio" value="0" <?php checked( $feat, '0' ); ?> />Si<br>
<input name="feat" type="radio" value="1" <?php checked( $feat, '1' ); ?> />No
With that change if $feat is '0' then the first checked will run, and if it's '1' the second will run.
I am trying to create 2 raido buttons as a category custom field, and in function.php I do:
$feat = get_term_meta( $tag->term_id, '_feat', true );
<input name="feat" type="radio" value="0" <?php checked( '0' ); ?> />Si<br>
<input name="feat" type="radio" value="1" <?php checked( '1' ); ?> />No
And then I do
if ( isset( $_POST['feat'] ) )
update_term_meta( $_POST['tag_ID'], '_feat', $_POST['feat'] );
But I always get "No" as checked
I am trying to create 2 raido buttons as a category custom field, and in function.php I do:
$feat = get_term_meta( $tag->term_id, '_feat', true );
<input name="feat" type="radio" value="0" <?php checked( '0' ); ?> />Si<br>
<input name="feat" type="radio" value="1" <?php checked( '1' ); ?> />No
And then I do
if ( isset( $_POST['feat'] ) )
update_term_meta( $_POST['tag_ID'], '_feat', $_POST['feat'] );
But I always get "No" as checked
Share Improve this question asked Nov 23, 2018 at 12:12 rob.mrob.m 2072 silver badges9 bronze badges1 Answer
Reset to default 2The purpose of checked() is to output a checked="checked" attribute based on a current value. By using it the way you're using it there you're forcing Si to never be checked and No to always be checked.
So what you want to do is use both arguments of checked() to compare the value of the input to the current value:
<input name="feat" type="radio" value="0" <?php checked( $feat, '0' ); ?> />Si<br>
<input name="feat" type="radio" value="1" <?php checked( $feat, '1' ); ?> />No
With that change if $feat is '0' then the first checked will run, and if it's '1' the second will run.
本文标签: functionsHow to get correct value from checked()
版权声明:本文标题:functions - How to get correct value from checked()? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749156611a2324702.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论