Archived topic
ACF True/False
3 replies · Started by Pete Williams on March 22, 2023
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
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
Perfect. Thank you, Fernando. Fantastic support!
You're welcome, Pete!