• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

How to display ACF fields with category posts

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › How to display ACF fields with category posts

This topic is: not resolved

Tagged: ACF, Custom fields, genesis_get_custom_field, get_post_meta

  • This topic has 22 replies, 3 voices, and was last updated 9 years, 9 months ago by Bart van Maanen.
Viewing 3 posts - 21 through 23 (of 23 total)
← 1 2
  • Author
    Posts
  • September 30, 2016 at 11:15 am #193997
    Brad Dalton
    Participant

    Just wrap it in a div like this:

    add_action( 'genesis_entry_content', 'custom_field_credits' );
    function custom_field_credits() {
    
    if ( ! is_single() && in_category( 'films' ) ) 
    		return;
    
            $title = genesis_get_custom_field( 'title' );
    	$product = genesis_get_custom_field( 'product' );
    	
    	echo'<div class="content-box-red">';
    	
    if ( $title ) {
    	printf( '<div class="credits">%s</div>', $title );
        }
    
    if ( $product ) {
    	printf( '<div class="credits">%s</div>', $product );
        }
        
        echo'</div>';
    
    }
    

    Then add the CSS for the colored content boxes


    Tutorials for StudioPress Themes.

    October 3, 2016 at 10:35 am #194163
    Bart van Maanen
    Participant

    Hi Brad,
    Lost you on Friday because we're in a different time zone.

    So, I now got this code working, only styled with a strong heading:

    add_action( 'genesis_entry_content', 'credits' );
    function credits() {
    if ( ! is_single() && in_category( 'films' ) ) 
    				return;
    				
    $titel = get_post_meta( get_the_ID(), 'titel', true );
    if( ! empty( $titel ) ) {
    echo '<strong><div class="credits">'. $titel .'</strong></div>';
    }
    $productie = get_post_meta( get_the_ID(), 'productie', true );
    if( ! empty( $productie ) ) {
    echo '<div class="credits">'. $productie .'</div>';
    }
    $regie = get_post_meta( get_the_ID(), 'regie', true );
    if( ! empty( $regie ) ) {
    echo '<div class="credits">'. $regie .'</div>';
    }
    }

    Then I tried the printf code above with the div for a content box, like this:

    add_action( 'genesis_entry_content', 'credits' );
    function credits() {
    
    if ( ! is_single() && in_category( 'films' ) ) 
    			return;
    	
        $titel = genesis_get_custom_field( 'titel' );
    	$productie = genesis_get_custom_field( 'productie' );
    	$regie = genesis_get_custom_field( 'regie' );
    	
    	echo'<div class="content-box-red">';
    	
    if ( $titel ) {
    	printf( '<div class="credits">%s</div>', $titel );
        }
    
    if ( $productie ) {
    	printf( '<div class="credits">%s</div>', $productie );
        }
    
    f ( $regie ) {
    	printf( '<div class="credits">%s</div>', $regie );
        }
        
        echo'</div>';
    
    }

    That returned a white screen I'm afraid.
    I replaced it with the get_post_meta code again and tried to style it with

    echo'<div class="content-box-red">';
     echo'</div>';

    But then only the title ( 'titel' ) was in the content-box-red settings.

    Any idea why the code with genesis_get_custom_fields won't do it?

    October 13, 2016 at 5:58 am #194636
    Bart van Maanen
    Participant

    Hi Brad, and everybody else interested,

    I combined some code from Brad to show ACF fields for a specific category and the show up as intended. But the styling - a content box - shows up empty on all post and pages, though the code should address the category 'films' only. The printf method didn't seem to be working.

    The site is over here: http://www.mokumfilm.nl/

    Now in functions.php is the following code:

    //* Maak Advanced Custom Fields Film Credits zichtbaar voor categorie Films
    add_action( 'genesis_entry_content', 'credits' );
    function credits() {
    if ( ! is_single() && in_category( 'films' ) ) 
    				return;
    				
    		echo'<div class="content-box-red">';
    						
    $titel = get_post_meta( get_the_ID(), 'titel', true );
    if( ! empty( $titel ) ) {
    echo '<div class="credits">'. $titel .'</div>';
    }
    $regie = get_post_meta( get_the_ID(), 'regie', true );
    if( ! empty( $regie ) ) {
    echo '<div class="credits">'. ' Regie:&nbsp; ' . $regie .'</div>';
    }
    $scenario = get_post_meta( get_the_ID(), 'scenario', true );
    if( ! empty( $scenario ) ) {
    echo '<div class="credits">'. ' Scenario:&nbsp; ' . $scenario .'</div>';
    }
    $camera = get_post_meta( get_the_ID(), 'camera', true );
    if( ! empty( $camera ) ) {
    echo '<div class="credits">'. ' Camera:&nbsp; ' . $camera .'</div>';
    }
    $geluid = get_post_meta( get_the_ID(), 'geluid', true );
    if( ! empty( $geluid ) ) {
    echo '<div class="credits">'. ' Geluid / sound design:&nbsp; ' . $geluid .'</div>';
    }
    $muziek = get_post_meta( get_the_ID(), 'muziek', true );
    if( ! empty( $muziek ) ) {
    echo '<div class="credits">'. ' Muziek:&nbsp; ' . $muziek .'</div>';
    }
    $montage = get_post_meta( get_the_ID(), 'montage', true );
    if( ! empty( $montage ) ) {
    echo '<div class="credits">'. ' Editor:&nbsp; ' . $montage .'</div>';
    }
    $producent = get_post_meta( get_the_ID(), 'producent', true );
    if( ! empty( $producent ) ) {
    echo '<div class="credits">'. ' Producent:&nbsp; ' . $producent .'</div>';
    }
    $cast = get_post_meta( get_the_ID(), 'cast', true );
    if( ! empty( $cast ) ) {
    echo '<div class="credits">'. ' Met:&nbsp; ' . $cast .'</div>';
    }		
    		echo'</div>';
    }

    Your tips and advice are greatly appreciated. Thanks Bart

  • Author
    Posts
Viewing 3 posts - 21 through 23 (of 23 total)
← 1 2
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble