Support

Account

Home Forums General Issues get_field("category")->name not working

Solving

get_field("category")->name not working

  • So I recently updated all plugins on a client’s website but suddenly I can’t get the value of a page’s category anymore. It shows all images now, instead of images per category because it returns an empty string.

      $category_field = get_field('category');
      $category = $category_field->name;
      $posts = get_posts_by_category($category);

    When I echo $category, it displays nothing. Am I doing something wrong?

  • Update: when I do the following:

    print_r('$category_field')

    it shows: Array ( [0] => 31 )

    So basically there’s is no content such as ‘name’ or ‘description’.. It was there before because it worked.

  • Check the settings on the field you are trying to get. It looks like it is returning term IDs instead of terms.

    Also, there may have been a change. ACF 5 always returns an array of terms or term IDs, deepening on the return value set in the field’s settings.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘get_field("category")->name not working’ is closed to new replies.