保存多个复选框元数据 WordPress

发布于 2024-11-04 06:18:40 字数 1611 浏览 0 评论 0原文

代码有效!

我有两种自定义帖子类型:事件艺术家。我正在使用 WPAlchemy MetaBox PHP 类,尝试在 Events 中创建一个带有一系列动态创建的复选框的元框(即每个 Artists 帖子都会有一个复选框)帖子编辑器允许我选择出现在活动中的艺术家

非常感谢任何帮助或见解!谢谢!

此代码可以很好地显示复选框(来自 checkbox_meta.php):

<div class="my_meta_control">

    <label>Group checkbox test #2</label><br/>

        <?php
        global $post;
        $artists = get_posts('post_type=artists');
        foreach($artists as $artist) :
        setup_postdata($artist);
        $slug = $artist->post_name;
        ?>

        <?php $mb->the_field('cb_ex2', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?>

        <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $slug; ?>"<?php $mb->the_checkbox_state($slug); ?>/><?php echo $artist->post_title; ?><br/>

    <?php endforeach; ?>

    <input type="submit" class="button-primary" name="save" value="Save">

</div>

此代码来自functions.php:

include_once 'assets/functions/MetaBox.php';
if (is_admin()) wp_enqueue_style('custom_meta_css', 'wp-content/themes/bam/assets/css/meta.css');

define('THEMEASSETS', STYLESHEETPATH . '/assets');

$custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'types' => array('sp_events'),
    'template' => THEMEASSETS . '/functions/checkbox_meta.php'
));

Code works!

I have two custom post types: Events and Artists. I'm using WPAlchemy MetaBox PHP class , trying to create a metabox with a series of dynamically created checkboxes (i.e. there will be a checkbox for each Artists post) in the Events post editor that will allow me to select which Artists are appearing at an Event.

Any help or insight much appreciated! Thanks!

This code works fine to display the checkboxes (from checkbox_meta.php):

<div class="my_meta_control">

    <label>Group checkbox test #2</label><br/>

        <?php
        global $post;
        $artists = get_posts('post_type=artists');
        foreach($artists as $artist) :
        setup_postdata($artist);
        $slug = $artist->post_name;
        ?>

        <?php $mb->the_field('cb_ex2', WPALCHEMY_FIELD_HINT_CHECKBOX_MULTI); ?>

        <input type="checkbox" name="<?php $mb->the_name(); ?>" value="<?php echo $slug; ?>"<?php $mb->the_checkbox_state($slug); ?>/><?php echo $artist->post_title; ?><br/>

    <?php endforeach; ?>

    <input type="submit" class="button-primary" name="save" value="Save">

</div>

This code from functions.php:

include_once 'assets/functions/MetaBox.php';
if (is_admin()) wp_enqueue_style('custom_meta_css', 'wp-content/themes/bam/assets/css/meta.css');

define('THEMEASSETS', STYLESHEETPATH . '/assets');

$custom_metabox = new WPAlchemy_MetaBox(array
(
    'id' => '_custom_meta',
    'title' => 'My Custom Meta',
    'types' => array('sp_events'),
    'template' => THEMEASSETS . '/functions/checkbox_meta.php'
));

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里南柯 2024-11-11 06:18:40

我开发了一个帮助器类,它可以帮助您创建 WordPress 元框

I've developed a helper class which might help you with creating wordpress meta boxes.

感情旳空白 2024-11-11 06:18:40

我认为这行是问题

$data = stripslashes_deep($_POST['artist']);

尝试将其更改为

$data = stripslashes_deep($_POST);

I think this line is the problem

$data = stripslashes_deep($_POST['artist']);

Try to change it to

$data = stripslashes_deep($_POST);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文