Home › Forums › Support › Advance Custom Field from category for my category archive header background?
- This topic has 16 replies, 2 voices, and was last updated 5 years, 1 month ago by
Elvin.
-
AuthorPosts
-
April 29, 2019 at 7:38 pm #883810
Melissa
Hi,
I’ve been using the code below to take a pic from a custom field on a post and use it as the hero image. (Works great! Thanks!) I also have this custom field for each category. Is there a way to set up a query for the category archive page to use that image?
add_filter( 'generate_page_hero_background_image_url', function( $url ) { $background_image = get_post_meta( get_the_ID(), 'hero_url', true ); if ( $background_image ) { $url = $background_image; } return $url; } );April 30, 2019 at 8:38 am #884520Tom
Lead DeveloperLead DeveloperHi there,
So you have a custom field in your categories?
According this this: https://www.advancedcustomfields.com/resources/taxonomy/
We should be able to do this:
add_filter( 'generate_page_hero_background_image_url', function( $url ) { $background_image = get_field( 'taxonomy_field_name' ); if ( $background_image ) { $url = $background_image; } return $url; } );Let me know 🙂
April 30, 2019 at 10:01 am #884630Melissa
No luck, alas.
https://theslowroad.org/category/destinations/south-america/ecuador/
(it should be an image of a fox in the grass)
Thanks so much for helping
April 30, 2019 at 10:08 am #884638Melissa
But that page is talking about a taxonomy field. I just have a url field (to the image) on each category. This is the same thing I did on the single posts, and that worked.
April 30, 2019 at 10:09 am #884640Melissa
(Oddly the Basic URL field isn’t one of the ones in that documentation.)
April 30, 2019 at 1:42 pm #884813Tom
Lead DeveloperLead DeveloperWhere is the URL field exactly? Is it on the page when you’re editing the category? Did you add the URL field using ACF?
April 30, 2019 at 1:44 pm #884817Melissa
I added it with ACF to the backend page where you edit the category.
April 30, 2019 at 2:03 pm #884844Tom
Lead DeveloperLead DeveloperSo that should work, although I’m not super familiar with ACF, so I could be wrong.
Did you replace
taxonomy_field_namein my code with the name you gave the field?If so, it might be worth checking with their support on how to get a field value from a category.
April 30, 2019 at 2:07 pm #884847Melissa
Okay, I’ll head over and ask them about it.
April 30, 2019 at 2:21 pm #884863Tom
Lead DeveloperLead DeveloperIf we know how to get the value, we can plug it into the filter.
Let me know 🙂
April 30, 2019 at 5:47 pm #884990Melissa
They pointed me here:
https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/April 30, 2019 at 5:50 pm #884992Melissa
I’ve got it working now! Thanks!
May 1, 2019 at 8:11 am #885682Tom
Lead DeveloperLead DeveloperAwesome! No problem 🙂
September 10, 2020 at 6:02 pm #1438713Samantha
This is exactly what I need to do and I can’t get it to work.
Could you please share what worked?
I use ACF, but unfortunately I am not a programmer, so the ACF instructions are like another language to me.
I have setup the ACF category image (shows on backend when editing categories and tags for my custom post type). My custome field name is: category_featured_image
Just can’t get it to show in Generatepress header.
Thanks in advance.
SamSeptember 10, 2020 at 7:59 pm #1438774Elvin
StaffCustomer SupportHi Sam,
Can you open a new topic for your question?
Thanks. 😀
-
AuthorPosts
- The topic ‘Advance Custom Field from category for my category archive header background?’ is closed to new replies.