Title: Illeagal string offset
Last modified: September 20, 2016

---

# Illeagal string offset

 *  Resolved [Wildcard](https://wordpress.org/support/users/thenewguy_14/)
 * (@thenewguy_14)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/illeagal-string-offset/)
 * Hey guys so on my front page i have a repeatable group field were i add all the
   services that my client provides.it works great and i even add a counter to break
   it up into three list. But then i need to add a portfolio section and i built
   my own custom post type for this as a plugin so that i could try and build out
   all the functionality myself and basically make my own plugin but when i try 
   and add the post via a shortcode or directly to the page it breaks the code some
   how and i get this error which his associated with the cmb2 out put array for
   the services provided
 * warning: Illegal string offset ‘service’ in /var/www/vhosts/avidbeta.com/httpdocs/
   wp-content/themes/wpBootStrap/front-page.php on line 75
 * Notice: Uninitialized string offset: 0 in /var/www/vhosts/avidbeta.com/httpdocs/
   wp-content/themes/wpBootStrap/front-page.php on line 75
 * but then when i remove that my shortcode the error goes away.
 * So i guessmy question is is it my custom post type code that is breaking everything
   or do i jsut not have the array set up correctly for the cmb2 fields…here is 
   that code
 *     ```
       <?php
           $services = get_post_meta( get_the_ID(), '_services_section_content', true );
                       $counter = 1;
                   foreach ( (array) $services as $key => $service ) {
                       if (isset($service['service']))
                       $serviceProvided = '';
                       $serviceProvided = esc_html( $service['service'] );
                       if( $counter%5 == 1){echo '<ul>';}?>
                       <li><?php echo $serviceProvided ?> </li>
                       <?php if( $counter%5 == 0){echo '</ul>';}
                       $counter++;
   
                       }
                       if ($counter%5 != 1) echo '</ul>';
                   ?>
       ```
   
 * I am at a loss on how to fix the array if that is what it is.
 * Thanks
    -  This topic was modified 9 years, 8 months ago by [Wildcard](https://wordpress.org/support/users/thenewguy_14/).

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [9 years, 8 months ago](https://wordpress.org/support/topic/illeagal-string-offset/#post-8203974)
 * What’s the returned variable value for $services on the first line? Curious if
   the array casting in the foreach loop is having an unintended effect here
 * Not sure how familiar you may be with functions like var_dump().
 *  Thread Starter [Wildcard](https://wordpress.org/support/users/thenewguy_14/)
 * (@thenewguy_14)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/illeagal-string-offset/#post-8204022)
 * i think we may have figured it out my shortcode was hijacking the the_post so
   i had to save the get_the_id to a variable
 *     ```
       <?php $post_id = get_the_ID();?>
       ```
   
 * change all the query’s for the cmb2 to post_id
 *     ```
       $contactHeadline = get_post_meta( $get_the_id(), '_fifth_section_content_headline', true ); 
       ```
   
 * to
 *     ```
       $contactHeadline = get_post_meta( $post_id, '_fifth_section_content_headline', true ); 
       ```
   
    -  This reply was modified 9 years, 8 months ago by [Wildcard](https://wordpress.org/support/users/thenewguy_14/).
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [9 years, 8 months ago](https://wordpress.org/support/topic/illeagal-string-offset/#post-8204180)
 * Sounds like things are good then. Let us know if something else comes up 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Illeagal string offset’ is closed to new replies.

 * ![](https://ps.w.org/cmb2/assets/icon.svg?rev=2866672)
 * [CMB2](https://wordpress.org/plugins/cmb2/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/cmb2/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/cmb2/)
 * [Active Topics](https://wordpress.org/support/plugin/cmb2/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/cmb2/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/cmb2/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/illeagal-string-offset/#post-8204180)
 * Status: resolved