Category output not working properly

Support MB Term Meta Category output not working properly

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #8414
    CreatieveMamaCreatieveMama
    Participant

    Hi there,

    First of all, I love the Meta Box plugin and extensions!

    But I am trying to add some stuff to my category pages and I can't get it to work.

    https://pastebin.com/VTnT6UuK

    I am using the following code to try to recieve the data from the fields:

    https://pastebin.com/7DVp50xf

    I'm trying to use this in two different websites. In one website it will show the image and other stuff on the category page, but it shows the data of one category on all category pages. So it won't reset and won't show the data of that specific category.

    On another website I'm using the exact same code and the data won't output at all.

    Can you tell me what I need to change to get this to work on both websites?

    #8421
    Anh TranAnh Tran
    Keymaster

    Hi,

    I think the problem comes from how you get the custom field data for categories. Basically, this loop:

    foreach ( $cats as $cat ) {
    	$term_id = $cat->term_id;
    }

    makes $term_id is always the ID of the last category. No matter how many categories, it always get the last category.

    That's why you always see the same data. Please take a look at that.

    #8423
    CreatieveMamaCreatieveMama
    Participant

    Thanks for putting me in the right direction!
    It's working perfectly now on both websites.

    I replaced this loop:

    foreach ( $cats as $cat ) {
    	$term_id = $cat->term_id;
    }

    with:
    $term_id = get_queried_object_id();

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Category output not working properly’ is closed to new replies.