Attach Files to Source Post

Attach GPML-imported files to the post from which the entry was submitted.

Code

Filename: gpml-attach-to-source-post.php

<?php
/**
 * Gravity Perks // Media library // Attach Files to Source Post
 * https://gravitywiz.com/documentation/gravity-forms-media-library/
 *
 * Attach GPML-imported files to the post from which the entry was submitted.
 */
add_filter( 'gpml_media_data', function( $media, $field, $entry ) {
	$media['post_parent'] = url_to_postid( $entry['source_url'] );
	return $media;
}, 10, 3 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.