[Resolved] Advance Custom Field from category for my category archive header background?

Home Forums Support [Resolved] Advance Custom Field from category for my category archive header background?

Home Forums Support Advance Custom Field from category for my category archive header background?

Viewing 15 posts - 1 through 15 (of 17 total)
  • Author
    Posts
  • #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;
    } );
    
    
    #884520
    Tom
    Lead Developer
    Lead Developer

    Hi 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 πŸ™‚

    #884630
    Melissa

    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

    #884638
    Melissa

    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.

    #884640
    Melissa

    (Oddly the Basic URL field isn’t one of the ones in that documentation.)

    #884813
    Tom
    Lead Developer
    Lead Developer

    Where is the URL field exactly? Is it on the page when you’re editing the category? Did you add the URL field using ACF?

    #884817
    Melissa

    I added it with ACF to the backend page where you edit the category.

    #884844
    Tom
    Lead Developer
    Lead Developer

    So that should work, although I’m not super familiar with ACF, so I could be wrong.

    Did you replace taxonomy_field_name in 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.

    #884847
    Melissa

    Okay, I’ll head over and ask them about it.

    #884863
    Tom
    Lead Developer
    Lead Developer

    If we know how to get the value, we can plug it into the filter.

    Let me know πŸ™‚

    #884990
    Melissa
    #884992
    Melissa

    I’ve got it working now! Thanks!

    #885682
    Tom
    Lead Developer
    Lead Developer

    Awesome! No problem πŸ™‚

    #1438713
    Samantha

    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.
    Sam

    #1438774
    Elvin
    Staff
    Customer Support

    Hi Sam,

    Can you open a new topic for your question?

    Thanks. πŸ˜€

Viewing 15 posts - 1 through 15 (of 17 total)
  • The topic ‘Advance Custom Field from category for my category archive header background?’ is closed to new replies.