Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2.  
  3. /*========================================
  4. =            Mysql connection            =
  5. ========================================*/
  6. $host_name = 'localhost';
  7. $username = 'root'; // Your database user name
  8. $password = 'root'; // Your password
  9. try {
  10.     $db_new = new PDO('mysql:host='.$host_name.';dbname=pte', $username, $password);
  11. } catch (PDOException $e) {
  12.     echo 'Error!: '.$e->getMessage().'<br/>';
  13.     die();
  14. }
  15. $db_new->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16. try {
  17.     $db_old = new PDO('mysql:host='.$host_name.';dbname=pte_wp2', $username, $password);
  18. } catch (PDOException $e) {
  19.     echo 'Error!: '.$e->getMessage().'<br/>';
  20.     die();
  21. }
  22.  
  23.  
  24.  
  25. // Get all posts where post type == 'post' (get all the news articles)
  26. $news = $db_old->prepare("SELECT * FROM `pte_posts` WHERE `post_type` = 'post'");
  27. $news->execute();
  28. $all_news = $news->fetchAll();
  29.  
  30. $attachments = $db_old->prepare("SELECT * FROM `pte_posts` WHERE `post_type` = 'attachment'");
  31. $attachments->execute();
  32. $all_attachments = $attachments->fetchAll();
  33.  
  34. $result = array_merge($all_news, $all_attachments);
  35.  
  36. $images = $db_old->prepare("SELECT * FROM `pte_postmeta` WHERE `meta_key` = 'featured_image'");
  37. $images->execute();
  38. $all_images = $images->fetchAll();
  39.  
  40. $slideshow = $db_old->prepare("SELECT * FROM `pte_postmeta` WHERE `meta_key` = 'slideshow'");
  41. $slideshow->execute();
  42. $slideshows = $slideshow->fetchAll();
  43.  
  44. $array = array();
  45.  
  46. foreach ($result as $row) {
  47.  
  48.     $test = $row['post_name'];
  49.  
  50.     foreach ($all_images as $image) {
  51.  
  52.         if ($image['meta_value'] == $row['ID']) {
  53.  
  54.             $array[] = array(
  55.                 'name' => 'kkj',
  56.                 'image' => $row['guid'],
  57.                 'post_id' => $image['post_id']
  58.             );
  59.  
  60.         }
  61.  
  62.         /*
  63.         if ($image['meta_value'] == $id) {
  64.  
  65.             $array[] = array(
  66.                 'name' => 'dunno',
  67.                 'image' => $row['guid'],
  68.                 'post_id' => $image['post_id']
  69.             );
  70.  
  71.         }
  72.         */
  73.  
  74.     }
  75.  
  76.     /*
  77.     foreach ($slideshows as $slideshow) {
  78.  
  79.         for($i = 0; $i < 10; ++$i) {
  80.             echo $i . ' ';
  81.         }
  82.  
  83.         if ($image['meta_value'] == $id) {
  84.  
  85.             $image_url = $row['guid'];
  86.  
  87.         }
  88.  
  89.     }
  90.     */
  91.  
  92. }
  93.  
  94. ?>
  95.  
  96. <pre>
  97.     <?php var_dump($array); ?>
  98. </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement