• Resolved Wildcard

    (@thenewguy_14)


    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.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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

    (@thenewguy_14)

    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.
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.