UPDATE #2
In your import_the_photos()
function, please change this:
// Copy the meta value (attachments) to the `v_editor` CPT.
$vid_pix = get_post_meta( $videoID, 'vid_pix', false ); // test
//delete_post_meta( $videoID, 'vid_pix' );
foreach ( $prop_att_ids as $att_id ) {
add_post_meta( $videoID, 'vid_pix', $att_id );
}
$vid_pix2 = get_post_meta( $videoID, 'vid_pix', false ); // test
var_dump( $vid_pix, $vid_pix2 ); // test
to:
// Get the attachments (IDs) attached to the `v_editor` CPT.
$vid_att_ids = (array) get_post_meta( $vidID, 'vid_pix', false );
// Copy/add the attachments to the `v_editor` CPT.
foreach ( $prop_att_ids as $att_id ) {
if ( $att_id && ! in_array( $att_id, $vid_att_ids ) ) {
add_post_meta( $vidID, 'vid_pix', $att_id );
}
}
var_dump( $prop_att_ids, $vid_att_ids, get_post_meta( $vidID, 'vid_pix', false ) ); // test
Apologize for the delete_post_meta()
, which thankfully you commented out..
Original Answer
(Old code removed, though.)
In your import-pics.php
file, add this before the $query = new WP_Query
line:
// Get the attachments (IDs) attached to the `property` CPT.
$prop_att_ids = (array) get_post_meta( $propertyID, 'imic_property_sights', false );
// Copy the meta value (attachments) to the `v_editor` CPT.
// OLD CODE HERE; REMOVED
But here’s the full code I used, where I don’t use the new WP_Query()
constructs:
<?php
// File: import-pics.php
require_once $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php';
$propertyID = $_POST['propertyID'];
$vidID = $_POST['videoID'];
// Get the attachments (IDs) attached to the `property` CPT.
$prop_att_ids = (array) get_post_meta( $propertyID, 'imic_property_sights', false );
// Copy the meta value (attachments) to the `v_editor` CPT.
// OLD CODE HERE; REMOVED
// Show a notice to the user.
echo '<p>Photos below have been imported ' .
'from <i>' . get_the_title( $propertyID ) . '</i> ' .
'to <i>' . get_the_title( $vidID ) . '</i>:</p>';
// And show the attachments.
foreach ( $prop_att_ids as $att_id ) {
$imgurl = $att_id ? wp_get_attachment_url( $att_id ) : '';
if ( $imgurl ) {
echo '<div style="display:inline-block;margin:10px;">';
echo '<a href="'.$imgurl.'"><img style="width:200px;" src="'.$imgurl.'"></a>';
echo '</div>';
}
}
// Show a "close" JS button..
echo '<p><a href="#" onclick="window.close(); return false;">Back to form</a></p>';
?>
PS: Updated because I forgot the meta imic_property_sights
and vid_pix
are added multiple times to a post. Sorry about that.