Created
March 13, 2014 16:19
-
-
Save jennschiffer/9531548 to your computer and use it in GitHub Desktop.
attachment meta copied into parent post meta woopwoop
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
<?php | |
// connect | |
$link = mysql_connect('lol', 'lmao', 'lmfao'); | |
if (!$link) { | |
die('Could not connect to mysql: ' . mysql_error()); | |
} | |
$wpDatabase = mysql_select_db("timelinedev", $link); | |
if (!$wpDatabase) { | |
die('Could not reach database: ' . mysql_error()); | |
} | |
// get all attachments | |
$attachmentResult = mysql_query("SELECT * FROM wp_posts WHERE post_type = 'attachment' AND post_mime_type = 'text/plain'") or die('error getting text attachments: ' . mysql_error()); | |
$attachmentCount = mysql_num_rows($attachmentResult); | |
echo $attachmentCount + ' text attachments'; | |
if ( $attachmentCount != 0 ) { | |
while ( $attachmentRow = mysql_fetch_array($attachmentResult) ) { | |
$postParent = $attachmentRow[post_parent]; | |
$attachmentID = $attachmentRow[ID]; | |
// get post meta from this attachment | |
$attachmentMetaResult = mysql_query("SELECT * FROM wp_postmeta WHERE post_id = $attachmentID AND meta_key = 'pdftext'") or die('error getting attachment meta: ' . mysql_error()); | |
$attachmentMetaCount = mysql_num_rows($attachmentMetaResult); | |
if ( $attachmentMetaCount != 0 ) { | |
while ( $attachmentMetaRow = mysql_fetch_array($attachmentMetaResult) ) { | |
$pdfMeta = addslashes($attachmentMetaRow['meta_value']); | |
// insert pdf meta into parent post meta | |
mysql_query("INSERT INTO wp_postmeta (post_id, meta_key, meta_value) VALUES ('$postParent', 'attachmentPDFText', '$pdfMeta')") or die('error inserting pdf meta: ' . mysql_error()); | |
} | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment