Support » Plugin: Getwid - Gutenberg Blocks » Custom field block only shows ID, not name in a ACF taxonomy field

  • Resolved xarz

    (@xarz)


    Hello.

    I’m using custom field block to try to show the taxonomy ACF field of a CPT in a custom template of your Custom Post Type block.

    I only get the ID of the custom field (regardless of option selected via ACF:object or ID) then I assume is a thing of custom field block.

    The Custom Field is of Radio Type, for your information.

    Can I show the Custom field name using some workarround?

    • This topic was modified 3 months, 4 weeks ago by xarz.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support eugenewhite

    (@eugenewhite)

    Hello there!

    Well, as I suggested in another topic, try customizing the “post-custom-field.php” file of the plugin with the code that I provided, and let me know if it was helpful or not. Or let me know if you have any additional questions.

    Thread Starter xarz

    (@xarz)

    Ok I supose I must dive in this code from: /includes/templates/template-parts/post-custom-field.php

    <?php
    
    //extract styles & classes
    extract($extra_attr);
    ?>
    
    <div class="<?php echo esc_attr( $wrapper_class ); ?>" <?php if ( !empty($wrapper_style) ) { ?> style="<?php echo esc_attr($wrapper_style); ?>" <?php } ?>>
        <?php if ( !empty($attributes['customField'] ) ) {
    		echo get_post_meta( get_the_ID(), esc_attr( $attributes['customField'] ), true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        } ?>
    </div>

    As I’m a newcomer to wordpress code I will need some time to render the taxonomy name.
    Let me try and I’ll post the results.

    Thank you very much!

    • This reply was modified 3 months, 3 weeks ago by xarz.
    Thread Starter xarz

    (@xarz)

    Done it! (perhaps in a not very right way, but it works 🙂

    For posterity:

    I modified the content of post-custom-field.php as suggested but I only formated my unformated fields, datetimes and customtaxonomy.
    Please forgive my base skills in this:
    <?php

    //extract styles & classes
    extract($extra_attr);
    ?>

    <div class=”<?php echo esc_attr( $wrapper_class ); ?>” <?php if ( !empty($wrapper_style) ) { ?> style=”<?php echo esc_attr($wrapper_style); ?>” <?php } ?>>
    <?php if ( !empty($attributes[‘customField’] ) ) {
    /* ORIGINAL CODE
    echo get_post_meta( get_the_ID(), esc_attr( $attributes[‘customField’] ), true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
    */
    $cfield=get_post_meta( get_the_ID(), esc_attr( $attributes[‘customField’] ), true );
    if (!empty($cfield)){
    if(strlen($cfield) == 2){
    $term= get_term($cfield);
    echo $term->slug;
    }else {
    if (strlen($cfield)==8){
    $year=substr($cfield,0,4);
    $month=substr($cfield,4,2);
    setlocale(LC_TIME, ‘es_ES.UTF-8’);
    $dateObj = DateTime::createFromFormat(‘!m’, $month);
    $timestamp=strtotime($cfield);
    echo date_i18n(“F Y “,$timestamp);
    }
    }
    }
    } ?>
    </div>

    Thanks!

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