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>';
} ?>
Recent Comments