Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to generate an array of custom post types to add it to a options array. I'm doing this to show a checkbox group populated with custom post type.

I have this array:

'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'  
    )  
)

How can i replace this with a custom post type? i'm trying this:

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

    $my_movies = get_posts( $args, ARRAY_A );

    return $my_movies;
}

I'm using the code in this article: Reusable Custom Meta Boxes Part 2

share|improve this question

1 Answer 1

up vote 0 down vote accepted

After getting the posts you can easily put them in another array & then return that array

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;
}
share|improve this answer
    
that works perfect! thk –  Oterox Nov 22 '12 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.