Function returning results twice

I’m using WordPress and built a custom post type to return a list of options from a comma separated list in the post, then create a set of checkboxes in a contact form 7 form. The function is working but for some reason it’s returning the output twice. I’m trying to figure out how to make it just return once.

wpcf7_add_shortcode('cargooptions', 'createbox', true);
function createbox(){

    global $post;

    $model = $_GET['mz'];

$args = array(
'post_type' => 'options',
'tax_query' => array(
    'relation' => 'AND',
        'taxonomy' => 'Opts_category',
        'field'    => 'slug',
        'terms'    => strtolower($model)



$myposts = get_posts( $args );

foreach ( $myposts as $post ) : setup_postdata($post);

        $options = explode(',', get_the_content());

        // output list
        foreach ($options as $key => $value){

            $output .= '<input type="checkbox" name="option_'.$key.'" value="'.$value.'" id="opt'.$key.'" class="optionSelect">';
            $output .= '<label for="opt'.$key.'"  class="span_4 colWrap"><span></span> ' . trim($value) . '</label>';

return $output;

Source: shortcode

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.