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 am using the custom meta box script from deluxeblogtips.com and I wondered if I could include get_posts within this array so that it displays all posts within a set post type ("Locations" for example)

array(
        'name' => 'Location',    // File type: checkbox
        'id' => $prefix . location',
        'type' => 'checkbox',
        'desc' => 'Check this box to make any links open in a new browser window',
        'std' => 0                      // Value can be 0 or 1
    ),

Obviously I'd need to be able to select as many posts as I wanted. Any help would be greatly appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I'm assuming there is an option in the array that is meant to receive an array of options for the checkboxes...?

In which case, you can use get_posts to obtain an array of post objects (of which ever type), and then loop through this, to create an array of post titles:

For example..

$args=array('numberposts'=>-1,'post_type' => 'location');
$post_objs = get_posts($args);
$options=array();

foreach($post_objs as $post_obj):
     $options[]=$post_obj->post_title;
endforeach;

You then have an array of location names, $options which you can feed into your metabox array.

Disclaimer: I've not tested this code.

share|improve this answer

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.