Getting PHP warning when condition is false

Home Forums WPAlchemy Getting PHP warning when condition is false

This topic contains 1 reply, has 1 voice, and was last updated by  alokjain_lucky 2 years, 11 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #2520


    I have created custom meta box using WPAlchemy class  to add option for related posts.

    Following code is working file in WP-Admin, and also in frontend only if i add related posts to the custom form created with meta box.

    However if i leave this empty, i am getting following warning message

    Warning: Illegal string offset ‘topics’ in /homepages/9/d416241127/htdocs/tw/u2me/wp-content/themes/u2me/single.php on line 37

    Here line 37 is if ($my_meta[‘topics’]) {

    in other words i am getting warning message when this condition should return false.

    I have used following code to create custom meta:

    <?php while($mb->have_fields_and_multi('topics')): ?>
    <?php $mb->the_group_open(); ?>

    <?php $mb->the_field('title'); ?>
    <p style="margin-top:0px;"><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>

    <?php $mb->the_field('link'); ?>
    <p style="margin-top:0px;"><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>

    <p><a href="#" class="dodelete button">Remove Topic</a></p>


    <?php $mb->the_group_close(); ?>
    <?php endwhile; ?>


    and used following code in single.php to show the values stored using above code:


    $my_meta = get_post_meta($post->ID,'_related_topics_meta',TRUE);

    if ($my_meta['topics']) {

    echo '<ul class="hero-subtitle">';

    foreach ($my_meta['topics'] as $topic) {


    <li><a href="<?php echo $topic['link']; ?>"><?php echo $topic['title']; ?></a></li>

    <?php     }

    echo '</ul>';

    } ?>



    I am getting formatting issues with code on this forum, maybe i am not posting it properly.

    I have also posted same question here:

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.