Support

Account

Home Forums General Issues How to show up coustom field of category in author.php

Solving

How to show up coustom field of category in author.php

  • I added a coustom field for category.

    it works fine in archive.php , here is code:

    <?php echo get_field('students_no_class', get_queried_object() );?>

    but it doesn’t work in author.php , nothing showup.

    in author page I need disaply coustom field value after

    <?php if (have_posts()) : while (have_posts()) : the_post();?>

    I guess get_field() need category id? not sure, also some of post coud belog to two categories.

    Thanks

  • Just did more test.

    When I delete author.php
    the author page will jump to archive page and coustom field value did not show up.
    (in archive.php I can see coustom field value)

    here is author page url:
    http://domianname.com/?author=123

    here is archive page url:
    http://domianname.com/?cat=456

  • Yes, if you want to get fields from a category and not the post then you must supply the category ID in the form of "term_{$term_id}" or you can supply the term object as in your first code example.

    You can get the terms of the post using get_the_terms()

  • Thanks for reply.
    but it looks doesn’t work. even i hard code the post id.

    <?php echo get_field('students_no_class', get_queried_object() , 456 ) ?>

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

You must be logged in to reply to this topic.