• Resolved bnfw

    (@voltronik)


    Hi,

    I’ve added an image field to a custom taxonomy called ‘image’ and i’m trying to retrieve it on a taxonomy template page (taxonomy-base_location.php in my case) but nothing is showing.
    Here’s my code:

    $cat_image = get_category_meta('image');
    var_dump($cat_image);

    All this outputs is string(0) ""
    Do you know what I’m doing wrong to not output anything?

    Thanks for any help in advance.

    https://www.ads-software.com/plugins/cfs-custom-category-fields/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author GatorDog

    (@gatordog)

    There are a couple things here to look at:

    1) I see that “image” is the name of your taxonomy. Is it also the name of the custom field? The first parameter to get_category_meta should be the name of field as defined in CFS.

    2) Internally, get_category_meta() relies on get_queried_object() to determine the relevant term. This may change if your page is doing anything with the global $wp_query object. You could try passing the term directly to the function to make sure this is not the issue:

    $term = get_queried_object();
    var_dump($term);
    $cat_image = get_category_meta('image', $term);
    var_dump($cat_image);
    Thread Starter bnfw

    (@voltronik)

    Thanks.
    My custom field is called ‘image’ and my taxonomy is called ‘base_location’.

    Doing:

    $term = get_queried_object();
    var_dump($term);

    outputs everything it should but when doing:

    $cat_image = get_category_meta('image', $term);
    var_dump($cat_image);

    it still only outputs string(0) "".

    Thread Starter bnfw

    (@voltronik)

    Ah, got it!
    I used get_terms() and then iterated through them and used echo wp_get_attachment_image($cat_image) to output the image from the custom field.

    Thanks for your help.

    Plugin Author GatorDog

    (@gatordog)

    Glad to hear you figured out something that works for your set up. In general practice, I think CFS has a setting where you can either return the attachment id or url from an image field. If you do just get_category_meta() it should simply return an array of all your fields, including the image field.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Getting term meta from a taxonomy template page’ is closed to new replies.