0

So I have a custom meta box which I'm trying to pull dynamic content through. I need to be able to loop through some posts pull that info and then store it into an array and then place those arrays within the options array shown below.

This is where I am at so far..

array(
        'label' => 'Overseeing Pastor',
        'id'    => $prefix.'pastor',
        'type'  => 'select',
        'options' => array (
            $args = array('post_type' => 'employee', 'position' => 'pastor');   
            $pastorList = new WP_Query($args); while ($pastorList->have_posts()) : $pastorList->the_post();
                array (
                    'label' => get_the_title(),
                    'value' => get_the_ID()
                ),
            endwhile; wp_reset_postdata();
        )
),

The options part is what I need help with. I understand that this obviously won't work. Is there a way to store the array as a varibale elsewhere then call for it in the options array? Appreciate any help, I'm ripping my hair out on this one.

1 Answer 1

1

Something like this?

$options = array();
$pastors = get_posts($args);

foreach ($pastors as $post) {
    $options[] = array(
        'label' => $post->post_title,
        'value' => $post->ID,
    );
}

or like this?

foreach ($pastors as $post) {
    $options[$post->post_title] = $post->ID;
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this worked perfect for what I need. Appreciate your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.