Created
December 9, 2021 23:38
-
-
Save schutzsmith/8586d736798c1abd2f7dbaa481569c8a to your computer and use it in GitHub Desktop.
ACF All Import Pro Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add custom field info to Media attachment after import from All Import Pro | |
*/ | |
function my_attachment_uploaded($pid, $attid, $filepath){ | |
$attachment = get_post($attid); | |
$embed_content = '<!-- wp:acf/pinellas-pdf-embed \{"id":"block_619bf48i9iq90ie09qi09e","name":"acf/pinellas-pdf-embed","data":\{"field_60da08c0ddbb4":"'.$attid.'"\},"align":"","mode":"preview"\} /-->'; | |
$prev_url = get_field(previous_url, $pid); | |
$prev_date = get_field(date_imported, $pid); | |
$prev_by = get_field(imported_by, $pid); | |
update_post_meta( $attid, 'previous_url', $prev_url ); | |
update_post_meta( $attid, 'date_imported', $prev_date ); | |
update_post_meta( $attid, 'imported_by', $prev_by ); | |
$my_image_meta = array( | |
'ID' => $pid, // Specify the image (ID) to be updated | |
'post_content' => $embed_content // Set image Caption (Excerpt) to sanitized title | |
); | |
wp_update_post( $my_image_meta ); | |
} | |
add_action('pmxi_attachment_uploaded', 'my_attachment_uploaded', 10, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment