Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将值从Wordpress元数据库发布到自定义分类_Php_Wordpress_Metadata_Meta Tags - Fatal编程技术网

Php 将值从Wordpress元数据库发布到自定义分类

Php 将值从Wordpress元数据库发布到自定义分类,php,wordpress,metadata,meta-tags,Php,Wordpress,Metadata,Meta Tags,我想知道是否有从wordpress metabox发布vales并将其添加到自定义非层次分类标签的方法 下面是自定义分类法的代码 // Custom taxonomy for Ingredients register_taxonomy( 'ingredients', 'mysite_tax', array( 'hierarchical' => false, 'label' => 'Ingredients',

我想知道是否有从wordpress metabox发布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>';
                                    }
                                ?>

不过,我想知道是否有办法将价值纯粹成分推送到自定义分类法中?

请参阅此评论及其后面的一些评论。

您可以查看更多信息,它包含了您真正需要的主题下的一些很好的参数

听起来你需要使用一个save_过滤器,尽管我想知道WPAlchemy是否是一种方法。花在学习WPAlchemy上的时间可以花在学习核心WordPressAPI和PHP上,从长远来看,这将更加有用。也就是说,如果您选择坚持使用WPAlchemy,下面是如何实现*save\u过滤器*

<?php

    $foo_meta_box = new WPAlchemy_MetaBox(array(
        'id' => '_custom_meta',
        'title' => 'My Custom Meta',
        'template' => TEMPLATEPATH . '/custom/meta.php',
        'save_filter' => 'foo_alchemy_save_filter'
    ));

    function foo_alchemy_save_filter($meta, $post_id) {
        unset($meta['ingredients']; // remove ingredients meta data before saving
        // do your custom taxonomy stuff using taxonomy API such as wp_set_object_terms() 
        return $meta;
    }

?>

您好,很高兴看到您的网站已恢复运行:。周末我一直在看这些评论,他们似乎想做与我想做的相反的事情。似乎他们想从自定义分类中获取术语,并将其拉入元数据库。我想将术语从元数据库中的特定字段推送到自定义分类法中。此外,我不能保存_的行动功能的权利,它不断打破我的网站。