Discovered how to display meta data on category.php
-
Just in case anybody encounters this issue. I’ve spent hours just trying to solve this. I’m not an in-depth php coder and so I’m sharing this just in case there are people out there like me who runs into this problem.
Using WordPress 3.1 and WP Category Meta 1.2.4. My goal was to add another description textarea field to my categories, to be displayed on my category pages (category.php) within the loop. The code I’ve followed is this:
<? $cat = $wp_query->get_queried_object(); $category_id = $cat->term_id; if (function_exists('get_terms_meta')) { &new_value = get_terms_meta($category_id, 'my_new_meta_data'); echo $new_value; } ?>
This code always displayed “Array” where I wanted my newly made and saved description to be. I then looked within the wp-category-meta.php and saw another variable get_terms_meta() was asking for besides $terms_id and $key. It was looking for a boolean variable $single. So I just tried to add one word in my get_terms_meta() and it was the word “true”. Here’s my new code:
<? $cat = $wp_query->get_queried_object(); $category_id = $cat->term_id; if (function_exists('get_terms_meta')) { &new_value = get_terms_meta($category_id, 'my_new_meta_data', true); echo $new_value; } ?>
get_terms_meta($category_id, ‘my_new_meta_data’, true) was all that was needed to get the data I’ve saved displayed on the page. Just add the word TRUE. I hope this helps a troubled soul out there.
- The topic ‘Discovered how to display meta data on category.php’ is closed to new replies.