• Resolved vectrus

    (@vectrus)


    After making a custom post block template and addingthe custom fields, i founnd that an image_with_crop filed from AdvancedCustomFields will always return:

    {“original_image”:”976″,”cropped_image”:”976″}

    Where notebly the quotes are not as the should be, and its not very useful. Is there an option to have a ‘custom_image_field’ postblock type? Or any other way around this otherwise very useful plugin?

    Please advise,
    julius

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

Viewing 1 replies (of 1 total)
  • alexandermatienkogmailcom

    (@alexandermatienkogmailcom)

    @vectrus

    For example you have a ‘Custom Field’ with the ‘Image’ type and ‘Field Name’ is ‘custom_image’.

    You can overwrite the template of ‘Custom Field’ block to display this image. Follow these steps:

    1. Copy file
    \wp-content\plugins\getwid\includes\templates\template-parts\post-custom-field.php
    to
    \wp-content\themes\%your-theme-name%\getwid\template-parts\post-custom-field.php

    where %your-theme-name% is your theme name.

    2. Open post-custom-field.php in the text editor and replace it with the code below. Change ‘custom_image’ with you own ‘Field Name’. Save.

    <?php
    //extract styles & classes
    extract($extra_attr);
    
    // replace custom_image with your ACF 'Field Name'
    if ( !empty( $attributes['customField'] ) && $attributes['customField'] === 'custom_image' ) {
    
    	$custom_image_src = '';
    
    	$custom_image_id = get_post_meta( get_the_ID(), esc_attr($attributes['customField']), true );
    	$custom_image_attributes = wp_get_attachment_image_src($custom_image_id);
    
    	if ($custom_image_attributes) {
    		?>
    		<div class="<?php echo esc_attr( $wrapper_class ); ?>" <?php echo (!empty($wrapper_style) ? 'style="'.esc_attr($wrapper_style).'"' : '');?>>
    			<img src="<?php echo $custom_image_attributes[0]; ?>" width="<?php echo $custom_image_attributes[1]; ?>" height="<?php echo $custom_image_attributes[2]; ?>" />
    		</div><?php
    	}
    } else {
    ?>
    <div class="<?php echo esc_attr( $wrapper_class ); ?>" <?php echo (!empty($wrapper_style) ? 'style="'.esc_attr($wrapper_style).'"' : '');?>>
        <?php echo (!empty($attributes['customField']) ? get_post_meta(get_the_ID(), esc_attr($attributes['customField']), true) : ''); ?>
    </div>
    <?php }
Viewing 1 replies (of 1 total)
  • The topic ‘custom_field ACF image in custom post block’ is closed to new replies.