简体   繁体   中英

How to display ACF custom field from category on author.php

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.

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:

get_field('your_acf_field_slug', 'category_123');

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:

<?php

$author_id = get_the_author_meta('ID');
$author_badge = get_field('author_badge', 'user_'. $author_id );

?>
<img src="<?php echo $author_badge['url']; ?>" alt="<?php echo $author_badge['alt']; ?>" />

Best regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM