【问题标题】:associate multiple post with one post in Wordpress将多个帖子与 Wordpress 中的一个帖子相关联
【发布时间】:2013-10-17 01:16:34
【问题描述】:

我正在管理区域的内容类型“团队”中创建一个元框,允许用户选中他们想要与他们正在创建的内容相关联的任何标题旁边的框。标题正在循环播放,它们来自不同的内容类型。

  array(
    'name' => __('Player List', 'theme_name'),
    'desc' => 'Select all the players that are on the team you are creating.',
    'id' => 'theme_name_players_completelist',
    'type' => 'checkbox',
    'options' => array(
        $args = array( 'post_type' => 'players');
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post();
        array('name' => __(the_title(), 'theme_name'), 'value' => 'get_the_ID()'),
      //But here is where I need to loop through and show the titles of the content type called team_members. The value could be the post ID or Title or whatever I guess.
         endwhile;
    )
  ),

这是完成此任务的唯一方法吗?

【问题讨论】:

    标签: php wordpress loops content-type


    【解决方案1】:

    我不确定你是否可以构建这样的数组,但可以简化为(未经测试):

    $posts = get_posts( array( 'post_type' => 'players') );
    $options = array();
    
    if( $posts ) {
        foreach( $posts as $post ) {
            $options[$post->ID] = $post->post_title;
        }
    }
    
    $the_array = array(
        'name' => __('Player List', 'theme_name'),
        'desc' => 'Select all the players that are on the team you are creating.',
        'id' => 'theme_name_players_completelist',
        'type' => 'checkbox',
        'options' => $options
      );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 2015-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-10
      相关资源
      最近更新 更多