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 1 year, 2 months ago.

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

    alokjain_lucky
    Participant

    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'); ?>
    <label>Title</label>
    <p style="margin-top:0px;"><input type="text" name="<?php $mb->the_name(); ?>" value="<?php $mb->the_value(); ?>"/></p>

    <?php $mb->the_field('link'); ?>
    <label>URL</label>
    <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>

    <br/>

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

    ——————————————————-

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

    <?php

    $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>';

    } ?>
     

    #2521

    alokjain_lucky
    Participant

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

    I have also posted same question here: http://stackoverflow.com/questions/14644352/getting-php-warning-when-condition-is-false

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

You must be logged in to reply to this topic.