检查来自自定义字段wordpress的广播框的值
问题描述:
我给了我的wordpress用户一个自定义字段在后端这是一个无线电选择三个值,1,2,3。检查来自自定义字段wordpress的广播框的值
我想设置条件,以便如果他们选择1,则出现图像1,如果他们选择2,则出现图像2,如果他们选择3,则图像3出现。
我目前使用下面显示的按钮检查所有thvalues - 但我需要使用不这样做,如果值= 1,则为此
<?php
/** Get a custom field with multiple values and return as an array */
$checkboxes_1 = get_custom_field('cft_checkboxes_1');
if($checkboxes_1) {
?>
<div id="block-1" class="content-box">
<h2>Custom Field (multiple)</h2>
<div class="entry">
<?php print_r($checkboxes_1); ?>
</div>
</div>
<?php } ?>
产生的custome字段中使用自定义字段模板按钮,并得到执行结果下降到kevin leary
我已经把这个在我的functions.php中检索从数据库中对自定义字段...
// Get Custom Field Template Values
function get_custom_field($field) {
global $post;
$custom_field_data = get_post_meta($post->ID, $field, false);
if($custom_field_data) {
if(count($custom_field_data) > 1) {
return $custom_field_data;
} else {
return $custom_field_data[0];
}
} else {
return false;
}
}
谢谢!
答
确定排序它感谢一个惊人的插件,一个伟大的黑客kevin leary:custom_field_templates
<?php
/** Get a custom field with multiple values and return as an array */
$checkboxes_1 = get_custom_field('mycustomfield');
if(($checkboxes_1) == 1) {
?>
// do something
<?php } else if(($checkboxes_1) == 2) {?>
// do something
<?php } else if(($checkboxes_1) == 3) { ?>
// do something
<?php } ?>
答
给予一定的值,单选按钮:
<input name="option" type="radio" value="1">
<input name="option" type="radio" value="2">
<input name="option" type="radio" value="3">
插入这些值到数据库,然后查询数据库,看看有什么是该领域的特定用户的价值。
+0
嗨 - 非常感谢 - 我理解需要做什么的原则......我想我在帖子中提到每个人都有价值。它不是必需的,我需要做什么,如何做到这一点! - 我更新了更多信息的问题 – JorgeLuisBorges
请问哪里在WordPress的法典“get_custom_field”正在不断记载?恕我直言,这不是一个WordPress代码? – smileBeda
哇 - 2011年的问题! 如果你在中途读过链接,那么不要涉及到自定义字段插件,而是谈论使用的插件和自定义字段检索的方法。 – JorgeLuisBorges