Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*========================================
- = Mysql connection =
- ========================================*/
- $host_name = 'localhost';
- $username = 'root'; // Your database user name
- $password = 'root'; // Your password
- try {
- $db_new = new PDO('mysql:host='.$host_name.';dbname=pte', $username, $password);
- } catch (PDOException $e) {
- echo 'Error!: '.$e->getMessage().'<br/>';
- die();
- }
- $db_new->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- try {
- $db_old = new PDO('mysql:host='.$host_name.';dbname=pte_wp2', $username, $password);
- } catch (PDOException $e) {
- echo 'Error!: '.$e->getMessage().'<br/>';
- die();
- }
- // Get all posts where post type == 'post' (get all the news articles)
- $news = $db_old->prepare("SELECT * FROM `pte_posts` WHERE `post_type` = 'post'");
- $news->execute();
- $all_news = $news->fetchAll();
- $attachments = $db_old->prepare("SELECT * FROM `pte_posts` WHERE `post_type` = 'attachment'");
- $attachments->execute();
- $all_attachments = $attachments->fetchAll();
- $result = array_merge($all_news, $all_attachments);
- $images = $db_old->prepare("SELECT * FROM `pte_postmeta` WHERE `meta_key` = 'featured_image'");
- $images->execute();
- $all_images = $images->fetchAll();
- $slideshow = $db_old->prepare("SELECT * FROM `pte_postmeta` WHERE `meta_key` = 'slideshow'");
- $slideshow->execute();
- $slideshows = $slideshow->fetchAll();
- $array = array();
- foreach ($result as $row) {
- $test = $row['post_name'];
- foreach ($all_images as $image) {
- if ($image['meta_value'] == $row['ID']) {
- $array[] = array(
- 'name' => 'kkj',
- 'image' => $row['guid'],
- 'post_id' => $image['post_id']
- );
- }
- /*
- if ($image['meta_value'] == $id) {
- $array[] = array(
- 'name' => 'dunno',
- 'image' => $row['guid'],
- 'post_id' => $image['post_id']
- );
- }
- */
- }
- /*
- foreach ($slideshows as $slideshow) {
- for($i = 0; $i < 10; ++$i) {
- echo $i . ' ';
- }
- if ($image['meta_value'] == $id) {
- $image_url = $row['guid'];
- }
- }
- */
- }
- ?>
- <pre>
- <?php var_dump($array); ?>
- </pre>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement