WordPress.org

Ready to get started?Download WordPress

Forums

Category Meta plugin
[resolved] Discovered how to display meta data on category.php (1 post)

  1. therealkentan
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic