0

i write code to get content from other site.

now I want save content in to wp_post of wordpress database..

date .. content.. titile ,..

wp_insert function wp_publish function

thise my php function..

      function writeMsg(){
    $result = mysql_query('SELECT * FROM `wp_farsc`');



    if($result && mysql_num_rows ($result)> 0){
  $data = null;
  $data.= '<table border="2px" cellspacing="5px" width="100%">'.PHP_EOL;
  $data.= '<tr bgcolor="yellow"><th>سکه</th><th>قیمت انلاین</th><th>تغییر قیمت</th><th>کمترین</th><th>بیشترین</th><th>زمان بروز رسانی</th></tr>'.PHP_EOL;

  while($row = mysql_fetch_assoc($result)){

     $data .='<tr>';
     $data .= '<td>'.$row ['titile'].'</td>';
     $data .='<td>'.$row ['liveprice'].'</td>';
     $data .='<td>'.$row ['changing'].'</td>';
     $data .= '<td>'.$row ['lowest'].'</td>';
     $data .= '<td>'.$row ['topest'].'</td>';
     $data .= '<td>'.$row ['time'].'</td>';
     $data .='</tr>'.PHP_EOL;
  }

  }

 mysql_close();
 return $data;
 }
  • first of all, you shouldn't use the mysql_ functions, they are deprecated and will eventually be removed from future php versions. WordPress has the wpdb class for querying other databases. as for your question, have you tried using wp_insert_post? – Milo Feb 7 '15 at 18:40
  • can you write example code to save content in wordpress with wp_insert_post function? – Mortzea Feb 7 '15 at 18:47
  • Why Codex examples of wp_insert_post usage doesn't satisfy you, @Mortzea? – Alexey Feb 7 '15 at 18:55
  • This post will help you. First and second answers are useful. wordpress.stackexchange.com/questions/8569/… – brs14ku Feb 7 '15 at 19:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.