• Resolved jejonesjnr

    (@jejonesjnr)


    I have a custom post type which has several image fields. When I create a form which allows attachments and link those fields to the ACF image fields, the images don’t embed. Instead, when I view the post, the image fields say “no image selected”. Is there something else I need to do?

Viewing 15 replies - 16 through 30 (of 43 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @jejonesjnr

    Can you please try this updated version https://gist.github.com/patrickfreitasdev/f5115dfe164a0e621d1f768ab7535eff

    you just need to update the line:

    $acf_fields = ['image_two', 'image_three', 'image_four'];

    And match your fields, https://monosnap.com/file/uvNNsFRuGAGs41wOQBZAV1MmaCE1yn

    Also the form_ids to ensure it will only run in specific forms.

    I tested the code using the shared ACF and Form without any modification and it worked well.

    Kindly let us know if it is working well on your end too.
    Best Regards
    Patrick Freitas

    Thread Starter jejonesjnr

    (@jejonesjnr)

    Thanks for the code update. I’m away on holiday for a week but I’ll try when I get back and feedback.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @jejonesjnr

    Sure thing, no problem, just let us know when you’re ready and we can get back to the case at any time.

    Best regards,
    Adam

    Thread Starter jejonesjnr

    (@jejonesjnr)

    I have updated the code in the mu-plugin folder.

    Ensured that the form ID has been updated and set the ACF fields to image with image ID selected. I have also ensured the form is set to save images in local media folder however, the images are still not being shown in the post details. It still says “no image selected” ??

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @jejonesjnr

    Thank you for response!

    We are testing codes that we are sharing and while there can be some (sometimes significant) differences between our test sites and the actual site the code is meant to be used on – there usually is a need for slight adjustments only.

    Yet, here nothing seems to work on your end and I’m starting to get the feeling that we are all missing something here. Probably some tiny but meaningful detail, specific to this case/your site.

    I’m just not sure yet what it is.

    Let me ask then:

    1. you mentioned it says “no image selected” – where exactly this shows, could you share a screenshot of that exact message (preferably “in context” of the site area where it shows)?

    2. if you can access your site’s database via phpMyAdmin
    – select the DB and go to “Search” tab
    – put this in search field

    %image_one%

    replacing image_one part with an actual field name of one of those mapped ACF fields (note: do keep the % characterse)

    – and run search

    Is it finding any records in “_postmeta” table then and if yes, do those records have value of “post_id” matching the posts created with Formiantor with mapped fields and our code used?

    Kind regards,
    Adam

    Thread Starter jejonesjnr

    (@jejonesjnr)

    I have placed 2 images in the folder below. One shows the custom post from within the WordPress dashboard. The other shows the corresponding DB entry for the post ID. You can see that the image_two field is blank which implies that no data is being transferred using the revised code within the mu-plugin directory.

    https://1drv.ms/f/s!AsElALC9XunfmDI0mlAxkEscoqvB?e=zhXgIz

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @jejonesjnr

    Thanks for response!

    I see that the form that you shared earlier is no longer available and I didn’t keep the copy of it so can’t check it. But I was working today on a similar thing for ACF and also struggled with pretty much the same issue until I realized that some of the upload fields on the form were set to “single” upload (those were working fine) and some to “multiple” upload – those require different code.

    So just to make sure:

    – all the ACF image fields have their corresponding form upload fields not only set in the custom code but also mapped in “postdata” field on the form?
    – are all of those upload fields on form set to “single” upload or are same (specifically those that have missing images) set to “multiple” upload (even if they have limit set to 1 file)?

    Kind regards,
    Adam

    Thread Starter jejonesjnr

    (@jejonesjnr)

    I have attached a couple more screen shots and a video showing my custom post type and the how the forminator form maps back to it.

    The image fields are set to single image as you suggest but the image is still not being transferred across.

    I have also reattached the json file and form export for you to reimport into your test environment.

    https://1drv.ms/f/s!AsElALC9XunfmDI0mlAxkEscoqvB?e=zhXgIz

    • This reply was modified 1 year, 9 months ago by jejonesjnr.
    • This reply was modified 1 year, 9 months ago by jejonesjnr.
    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @jejonesjnr

    Hope you are doing fine!

    I have imported the Advanced Custom Fields Calendar Competition Field Group json file and the Forminator export. I went through the name of the fields and also the mapping settings and they seem to be fine. There is an additional piece of information that can help us, could you share screenshots or export the custom port type definition? It seems you are using CPT UI for the custom type management (correct me if I am wrong)

    With this information we can setup the complete scenario as you have it in your site and perform additional tests.

    Let us know once you have the export ready in the OneDrive folder so we can provide additional assistance.

    Kind regards

    Luis

    Thread Starter jejonesjnr

    (@jejonesjnr)

    I’m not sure how to obtain what you’re after. Can you advise please?

    You are correct, I used CPT UI to creates the custom post type.

    • This reply was modified 1 year, 9 months ago by jejonesjnr.
    Thread Starter jejonesjnr

    (@jejonesjnr)

    I have added an extract of code into the folder. Not sure of this is what you’re loooking for?

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @jejonesjnr

    Thanks for the CPT register code.

    We’ll perform some additional tests with the file you just added. However, to make sure we have an accurate copy of the settings in your site, it’d be recommended to include the export file as indicated in the image below:

    https://snipboard.io/Hrdgby.jpg

    Let us know once the CPT UI file is added to the One Drive shared folder. Meanwhile, I have shared the export files with our Second Level Team to perform a further check. Once we have an update, a reply will be added in this thread.

    Kind regards

    Luis

    Thread Starter jejonesjnr

    (@jejonesjnr)

    I have included a file called “Export from CPT UI”. Be aware that there are two post types included within the code.

    Plugin Support Saurabh – WPMU DEV Support

    (@wpmudev-support7)

    Hi @jejonesjnr

    I have shared this information with our Second Level Support team as well so they can include it in any additional testing they perform.

    Please keep in mind their response may take some considerable time. Once they give us an update, a reply will be included in this thread.

    Kind regards

    Luis

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @jejonesjnr,

    Could you please make sure to enable the Show files in media library option in the Upload fields settings:

    Screenshot at 16:44:33.png

    And then apply the following snippet and see whether it works fine?

    <?php
    
    add_action( 'forminator_post_data_field_post_saved', 'wpmudev_update_post_acf_upload', 10, 4 );
    function wpmudev_update_post_acf_upload( $post_id, $field, $data, $cls ) {
    	// comma separated list of image fields
    	$image_fields = array( 'image_two', 'image_three', 'image_four', 'image_five', 'image_six', 'image_seven', 'image_eight', 'image_nine', 'image_ten' ); 
    
    	if( isset( $data['post-custom'] ) ){
    		foreach( $data['post-custom'] as $pkey => $pval ){
    			
    			if ( in_array( $pval['key'], $image_fields ) ) {
    			
    				if( $pval['value'] ) {
    					$attach_id = attachment_url_to_postid( $pval['value'] );
    					if( $attach_id ) {
    						update_field($pval['key'], $attach_id, $post_id);
    						$mime_type = wp_get_image_mime( $pval['value'] );
    						if( $mime_type ) {
    							$update_data = array(
    								'ID' => $attach_id,
    								'post_mime_type' => $mime_type,
    							);
    							wp_update_post( $update_data );
    						}
    					}
    				}
    			}
    		}
    	}
    }

    You can add the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,

    Nithin

Viewing 15 replies - 16 through 30 (of 43 total)
  • The topic ‘Issue with images’ is closed to new replies.