I added a custom field for category.
It works fine in archive.php, here is the code:
<?php echo get_field('students_no_class', get_queried_object() );?>
but it doesn’t work in author.php, nothing shows up.
In author page I need display custom field value after
<?php if (have_posts()) : while (have_posts()) : the_post();?>
I also did a test:when I delete author.php, the author page will use archive.php template and the custom field show up nothing.
2
Answers
If you want to display custom field’s value on the basis of the category, first you will have to get category ID based on the post ID and then you will have to provide the category id as per below example:
Here is the reference link:
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/
if you want to retrieve user/author related acf fields you have to supply the author id ACF Documentation explains how to use it.
an example would something like this:
Best regards