【问题标题】:use custom post type as a field in other custom post type使用自定义帖子类型作为其他自定义帖子类型中的字段
【发布时间】:2013-12-12 01:11:20
【问题描述】:

这就是我在functions.php中定义的战争

function create_post_type(){
    register_post_type('my_persons', 
        array('labels' => 
            array(
                'name' => __('Persons'),
                'singular_name' => __('Person')
            ),
            'public' => true,
            'menu_position' => 5,
            'rewrite' => array('slug' => 'persons'),
             'supports' => array('title', 'editor','thumbnail')
        )
    );
    register_post_type('my_shoes', 
        array('labels' => 
            array(
                'name' => __('Shoes'),
                'singular_name' => __('Shoe')
            ),
            'public' => true,
            'menu_position' => 6,
            'rewrite' => array('slug' => 'shoes'),
             'supports' => array('title', 'editor')
        )
    );
    }
add_action('init', 'create_post_type');

我想要做的是,当添加一个新人时,我想查看(已添加)鞋子的列表并选择(通过复选框)他拥有的鞋子。

我已经安装了“高级自定义字段”插件。我知道可以在其中定义鞋子的复选框列表并将其用作人员的字段。但我希望在添加新的“鞋子”自定义帖子时动态填充此字段。

这很难解释,但我想你明白了。顺便说一句,我正在使用 Wordpress 3.7.1,对此我完全陌生。

任何帮助表示赞赏;-)

【问题讨论】:

  • 我认为这个插件已经有一个custom_post_types的下拉列表..
  • 如果有,我找不到了。
  • 我将复选框与下拉菜单混淆了。它有一个名为 post_object 的选项来生成 Dropdown (我认为不是复选框..),但请查看我的答案。您可以轻松过滤复选框。

标签: wordpress field custom-post-type dynamically-generated


【解决方案1】:

在此处查看Documentation

您需要使用过滤器my_acf_load_field( $field ),然后查询您的自定义帖子类型shoes:例如

 query_posts(array( 
        'post_type' => 'shoes',
        'showposts' => 10 
    ) );  

然后像文档中的代码示例一样填充字段数组。

【讨论】:

    猜你喜欢
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 2016-11-29
    • 2014-03-02
    相关资源
    最近更新 更多