• Is there a way to get MFB to change how it is displaying an ACF date field on a per-block basis?
    We need to display the same ACF date field differently depending on if it’s the event CPT archive page or the CPT single post. Using meta_field_block_get_acf_fieldwill, I guess, change how the field is displayed for all instances?

    I sort of thought that I can change this on a per-block basis in MFB, but haven’t found this: ?I’m going to do a setting allowing to choose the output format of the block soon?… maybe I’m looking in the wrong place?

    Thanks!

    • This topic was modified 1 day, 5 hours ago by philbee.
Viewing 1 replies (of 1 total)
  • Plugin Author Phi Phan

    (@mr2p)

    Hi @philbee,

    I intended to add that setting to the block, but then I changed my mind. I want to keep the logic and UI of this block simple. Most of the rare cases can be handled easily with custom code. In your case, you can display different date formats between contexts by using conditional tags.

    You can adjust the following sample code to display different formats for your field:

    add_filter(
    'meta_field_block_get_acf_field',
    function ( $block_content, $post_id, $field, $raw_value, $object_type ) {
    // Replace
    your_date_field with your unique name.
    if ( $block_content && 'your_date_field' === ( $field['name'] ?? '' ) ) {
    // You can use conditional tags to determine the field context.
    if ( is_single() ) {
    // Change your date format here.
    return date( 'm/d/Y', strtotime( $block_content ) );
    } else {
    // Change your date format here.
    return date( 'd/m/Y', strtotime( $block_content ) );
    }
    }

    return $block_content;
    },
    10,
    5
    );

    Best, Phi.

    • This reply was modified 1 day, 1 hour ago by Phi Phan.
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.