Advertisement
Guest User

Untitled

a guest
May 26th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. $query5 = "SELECT ID FROM wp_posts WHERE post_name='".$post_id."'";
  2.  
  3.  
  4. $checkpost= mysqli_num_rows( mysqli_query($conn_link,$query5));
  5. //check if post exist
  6. if ($checkpost <= 0 && $type=="photo") {
  7.  
  8. $query = "INSERT INTO wp_posts (post_author,post_link, post_date, post_date_gmt,post_content,post_title,post_status,post_name,post_modified,post_modified_gmt)
  9. VALUES ('1', '".$postlink."','".$converted_date_time."', '".$converted_date_time."', '".$content."', '".$titl."', 'publish', '".$post_id."', '".$converted_date_time."', '".$converted_date_time."')";
  10.  
  11.  
  12. if (mysqli_query($conn_link,$query) === true)
  13.  
  14. {
  15. echo"Add post done <br>";
  16.  
  17.  
  18. } else
  19. {
  20. echo"No posts add";
  21. echo"<br>";
  22. echo mysqli_error($conn_link);
  23. }
  24.  
  25. $query = "SELECT ID FROM wp_posts WHERE post_name='".$post_id."'";
  26.  
  27. $row = mysqli_fetch_row(mysqli_query($conn_link, $query));
  28.  
  29. $postid=$row[0];
  30.  
  31. echo "post id is ".$postid."<br>" ;
  32.  
  33. $query = "UPDATE wp_posts SET guid='http://xxxx.com/?p=".$postid."' where ID='".$postid."'";
  34.  
  35. if (mysqli_query($conn_link,$query) === true)
  36.  
  37. {
  38. echo"Done UPDATE wp_posts ";
  39.  
  40.  
  41. } else
  42. {
  43. echo"Error in UPDATE wp_posts ";
  44. }
  45.  
  46.  
  47. //Add image
  48. $query = "INSERT INTO wp_posts (post_type, guid, post_status, post_mime_type,post_parent,post_name,post_title,post_modified,post_modified_gmt)
  49. VALUES ('attachment', '".$actual_link."', 'inherit', 'image/jpeg', '".$postid."','".$tn."','".$tn."', '".$converted_date_time."', '".$converted_date_time."')";
  50.  
  51. //check query
  52. if (mysqli_query($conn_link,$query) === true)
  53.  
  54. {
  55. echo"Add image done <br>";
  56. echo"<br>";
  57.  
  58. } else
  59. {
  60. echo"no image add";
  61. echo"<br>";
  62. echo mysqli_error($conn_link);
  63. echo"<br>";
  64. }
  65. //get image ID
  66. $query = "SELECT ID FROM wp_posts WHERE post_name='".$tn."'";
  67.  
  68. $row = mysqli_fetch_row(mysqli_query($conn_link, $query));
  69.  
  70. $imgid=$row[0];
  71.  
  72. //add postmeta to link image to post
  73. $query = "INSERT INTO wp_postmeta (meta_value, meta_key, post_id)
  74. VALUES ('".$imgid."','_thumbnail_id', '".$postid."')";
  75.  
  76.  
  77. //check query
  78. if (mysqli_query($conn_link,$query) === true)
  79.  
  80. {
  81. echo"Add image to post done <br>";
  82.  
  83.  
  84. } else
  85. {
  86. echo"no image add to post ";
  87. echo"<br>";
  88. echo mysqli_error($conn_link);
  89. echo"<br>";
  90. }
  91.  
  92.  
  93. //add postmeta to link image to post as _wp_attached_file
  94. $query = "INSERT INTO wp_postmeta (meta_value, meta_key, post_id)
  95. VALUES ('".$actual_link."','_wp_attached_file', '".$imgid."')";
  96.  
  97. //check query
  98. if (mysqli_query($conn_link,$query) === true)
  99.  
  100. {
  101. echo"Add image to post done <br>";
  102.  
  103.  
  104. } else
  105. {
  106. echo"no image add to post ";
  107. echo"<br>";
  108. echo mysqli_error($conn_link);
  109. echo"<br>";
  110. }
  111.  
  112.  
  113. //this part to link post with taxonomy
  114. echo"<br>";
  115. echo "trerm id is ".$term_id ;
  116. echo"<br>";
  117. $query7 = "SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE term_id='".$term_id."'";
  118. $taxonomy_id = mysqli_fetch_row(mysqli_query($conn_link, $query7));
  119. $taxonomy_id=$taxonomy_id[0];
  120.  
  121. $query = "INSERT INTO wp_term_relationships (object_id, term_taxonomy_id)
  122. VALUES ('".$postid."', '".$taxonomy_id."')";
  123.  
  124. if (mysqli_query($conn_link,$query) === true)
  125. {
  126. echo"Yes INSERT INTO dmo_term_relationships Yes ";
  127. } else
  128. {
  129. echo"No INSERT INTO dmo_term_relationships No";
  130. echo"<br>";
  131. echo mysqli_error($conn_link);
  132. echo"<br>";
  133. }
  134.  
  135.  
  136. }
  137.  
  138. a:5:{s:5:"width";i:640;s:6:"height";i:372;s:4:"file";s:13:"2013/03/7.jpg";s:5:"sizes";a:5:{s:9:"thumbnail";a:4:{s:4:"file";s:13:"7-150x150.jpg";s:5:"width";i:150;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:13:"7-300x174.jpg";s:5:"width";i:300;s:6:"height";i:174;s:9:"mime-type";s:10:"image/jpeg";}s:13:"helium_square";a:4:{s:4:"file";s:13:"7-640x372.jpg";s:5:"width";i:640;s:6:"height";i:372;s:9:"mime-type";s:10:"image/jpeg";}s:11:"helium_4by3";a:4:{s:4:"file";s:13:"7-400x300.jpg";s:5:"width";i:400;s:6:"height";i:300;s:9:"mime-type";s:10:"image/jpeg";}s:7:"480x480";a:3:{s:4:"file";s:13:"7-480x372.jpg";s:5:"width";i:480;s:6:"height";i:480;}}s:10:"image_meta";a:12:{s:8:"aperture";s:1:"0";s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";s:1:"0";s:9:"copyright";s:0:"";s:12:"focal_length";s:1:"0";s:3:"iso";s:1:"0";s:13:"shutter_speed";s:1:"0";s:5:"title";s:0:"";s:11:"orientation";s:1:"0";s:8:"keywords";a:0:{}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement