I've been tasked to fixed the wordpress web site problem for our client and almost everything is fixed except the part of the code that never display the background image.
I've been working the fix on my local computer and imported all the data from online. And below is the code I've tracing.
<?php
$taxonomies = get_all_category_ids();
var_dump($taxonomies);
$count = 1;
foreach ($taxonomies as $cat_id) {
$cats_id = intval($cat_id);
var_dump($cats_id);
$category = get_category($cats_id);
var_dump($category);
$cat_meta = get_option("category_$cats_id");
$image_cat = get_option("category_$cats_id");
var_dump($image_cat);
if ($category->parent == 9) {
$thumbnail_id = get_term_meta( $cats_id, 'wpfifc_featured_image', true );
$thumbnail_html = wp_get_attachment_url( $thumbnail_id, 'post-thumbnail' );
$categ_slug = $category->slug;
$categ_name = strtoupper($category->name);
if ($categ_slug == 'all-day-breakfast'): ?>
<div style="background-image:url(<?php echo $image_cat['img'];?>);background-size: 100%;" class="box_menu01 <?php echo $categ_slug?>" background>
<span>
<a href="<?php echo get_page_link(2) . "#" . $categ_slug; ?>"><?php echo $categ_name; ?></a>
</span>
</div>
<?php else: ?>
<div style="background-image:url(<?php echo $image_cat['img'] ?>);background-size: 100%;" class="box_menu02 <?php echo $categ_slug?>" background>
<span><a href="<?php echo get_page_link(2) . "#" . $categ_slug; ?>"><?php echo $categ_name; ?></a></span>
</div>
<?php endif; ?>
<?php $count++;
}
}
?>
Base on the var_dump result this
$image_cat = get_option("category_$cats_id");
part should return image path, because this being used in
<div style="background-image:url(<?php echo $image_cat['img'];?>);background-size: 100%;" class="box_menu01 <?php echo $categ_slug?>" background>
In online, image_cat
is an array with value image path, but in the local, its value is false
.
I've been looking anywhere in dashboard or using var_dump() but could not trace the problem. Is there someone here encounter the same problem?
$image_cat = get_option("category_$cats_id");
what is category_$cats_id
?
I think the code should be
$image_cat = get_option("category_".$cats_id."");