2012-11-22 59 views
0

我創建一個複選框組的metabox,我想用自定義帖子類型填充複選框。Wordpress metabox填充複選框組與自定義帖子類型

我使用本文中的代碼:Reusable Custom Meta Boxes Part 2

現在對於複選框組我有硬編碼值:

array ( 
    'label' => 'Sponsors', 
    'desc' => 'Sponsors for this exercise.', 
    'id' => $prefix.'sponsors', 
    'type' => 'checkbox_group', 
    'options' => array ( 
     'one' => array ( 
      'label' => 'Option One', 
      'value' => 'one' 
     ), 
     'two' => array ( 
      'label' => 'Option Two', 
      'value' => 'two' 
     ), 
     'three' => array ( 
      'label' => 'Option Three', 
      'value' => 'three' 
     ), 
     'four' => array ( 
      'label' => 'Option Four', 
      'value' => 'four' 
     ) 
    ) 
)  

和驗證碼保存數據:

case 'checkbox_group': 
foreach ($field['options'] as $option) { 
    echo '<input type="checkbox" value="'.$option['value'].'" name="'.$field['id'].'[]" id="'.$option['value'].'"',$meta && in_array($option['value'], $meta) ? ' checked="checked"' : '',' /> 
      <label for="'.$option['value'].'">'.$option['label'].'</label><br />'; 
} 

打破;

我想用一個自定義後類型加載複選框:

function get_sponsors() 
{ 
    $args = array(
    'numberposts' = -1, 
    'post_type' = 'px_sponsor', 
    'orderby' = 'post_title', 
    'order' = 'ASC' 
    ); 

    $my_sponsors = get_posts($args); 

    return $my_sponsors; 
} 

如何修改它,所以它顯示的,而不是硬編碼的那些我自定義後類型的值?

回答

0

解決!

我改變了功能get_sponsors(),以返回與職位的數組:

function get_sponsors() 
{ 
    $args = array(
    'numberposts' => -1, 
    'post_type' => 'movies' 
    ); 

    $my_movies = get_posts($args); 

    $options = array(); 
    foreach($my_movies as $m) 
     $options[$m->ID] = array(
      'label' => $m->post_title, 
      'value' => $m->ID 
     ); 

    return $options; 
} 

學分解決Mridul AGGARWAL對該post

回覆
相關問題