【发布时间】:2011-02-13 15:51:00
【问题描述】:
我想知道是否可以从 wordpress 元框中发布 vales 并将其添加到自定义的非分层分类法(标签)中。
这是自定义分类的代码
// Custom taxonomy for Ingredients
register_taxonomy(
'ingredients',
'mysite_tax',
array(
'hierarchical' => false,
'label' => 'Ingredients',
'query_var' => true,
'rewrite' => true
)
);
我目前正在使用 wpalchemy 元框,元框的代码是
<div class="my_meta_control">
<h4>Ingredients</h4>
<?php while($mb->have_fields_and_multi('recipe_ingredients')): ?>
<?php $mb->the_group_open(); ?>
<?php $mb->the_field('quantity'); ?>
<label>Quantity and Ingredients</label>
<p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>
<?php $mb->the_field('ingredients'); ?>
<p><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>
<?php $selected = ' selected="selected"'; ?>
<br/><?php $metabox->the_field('units',1); ?>
<select name="<?php $metabox->the_name(); ?>">
<option value="unit"<?php if ($metabox->get_the_value() == 'unit') echo $selected; ?>>--Select Unit--</option>
<option value="Test"<?php if ($metabox->get_the_value() == 'Test') echo $selected; ?>>Test</option>
<option value="Test2"<?php if ($metabox->get_the_value() == 'Test2') echo $selected; ?>>Test 2</option>
<option value="Test3"<?php if ($metabox->get_the_value() == 'Test3') echo $selected; ?>>Test 3</option>
</select>
<a href="#" class="dodelete button">Remove Document</a>
</p>
<?php $mb->the_group_close(); ?>
<?php endwhile; ?>
<p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-ingredients button">Add Document</a></p>
<br /><p><a style="float:right; margin:0 10px;" href="#" class="dodelete-ingredients button">Remove All</a></p>
</div>
我只想将成分字段中的值传递给自定义分类。我是一个php新手,所以它可能很容易,我没有意识到:)
我可以使用此代码获取页面模板中的值
<?php
// loop a set of field groups
while($ingredients_metabox->have_fields('recipe_ingredients'))
{
echo '<li>';
$ingredients_metabox->the_value('quantity');
$ingredients_metabox->the_value('ingredients');
$ingredients_metabox->the_value('units');
echo '</li>';
}
?>
但是我想知道是否有办法将值(只是成分)推入自定义分类?
【问题讨论】:
标签: php wordpress metadata meta-tags