Site logo

[Resolved] ACF True/False

Home Forums Support [Resolved] ACF True/False

Home Forums Support ACF True/False

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #2577738
    Pete Williams

    I’m using GP Premium and the free version of Generate Blocks.

    I’m trying to use a Query Loop to include a <span> container when a True/False custom field with the name ‘affiliate_link’ is set to Yes(True).

    Is this possible via code?

    I’ve tried a few different things, but all I can get to display is either 1 or 0 depending on whether True or False is selected.

    Thakn you for your help.

    Pete

    #2577817
    Fernando
    Customer Support

    Hi Pete,

    It’s should be possible.

    Try adding my-span-cont to the class list of the Container Block. Adding Custom Classes: https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/

    Then, add this Snippet:

    add_filter( 'render_block', function( $block_content, $block ) {
        if ( !is_admin() && ! empty( $block['attrs']['className'] ) && strpos( $block['attrs']['className'], 'my-span-cont' ) !== false ) {
    		$mybool = get_field( "affiliate_link", get_the_ID() );
    		if( !$mybool ) {
    			return '';
    		}
        }
    
        return $block_content;
    }, 10, 2 );

    Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets

    #2579302
    Pete Williams

    Perfect. Thank you, Fernando. Fantastic support!

    #2579548
    Fernando
    Customer Support

    You’re welcome, Pete!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.