-
Notifications
You must be signed in to change notification settings - Fork 0
/
setattachments.php
71 lines (53 loc) · 2.07 KB
/
setattachments.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require(dirname(__FILE__) . '/../wp-load.php');
require(dirname(__FILE__) . '/../wp-content/plugins/sitepress-multilingual-cms/sitepress.php');
//////////////////////////////// OPERATE ON QUERIED POSTS
$attachments = get_posts(array(
'post_type' => 'attachment',
'posts_per_page' => 1000000000
)
);
// foreach($attachments as $attachment) {
// $postid = $attachment->ID;
// $attachmenttitle = $attachment->post_title;
// print_r($attachment);
// echo '<br><br>';
// };
$matricules = get_posts(array(
'post_type' => 'matricule',
'posts_per_page' => 1000000000
// ,
// 'meta_query' => array(
// array(
// 'key' => 'related_events', // name of custom field
// 'value' => true, // matches exaclty "123", not just 123. This prevents a match for "1234"
// 'compare' => 'LIKE'
// )
// )
));
if ($matricules)
foreach($matricules as $matricule) {
$postid = $matricule->ID;
$posttitle = $matricule->post_title;
// print_r($posttitle);
// print_r(get_post_meta($postid));
// echo '<br>';
$attachmentsarray = array();
foreach($attachments as $attachment) {
// $attachmentid = $attachment->ID;
$attachmenttitle = $attachment->post_title;
if (strpos($attachmenttitle, $posttitle) !== false) {
$itsattachment = array(
"id" => $attachment->ID
);
$attachmentsarray[] = $itsattachment;
}
};
if (!empty($attachmentsarray)) {
$attachmentstoappend = array(
"my_attachments" => $attachmentsarray
);
update_post_meta($postid , 'attachments', json_encode( $attachmentstoappend ));
}
};
?>