wp_insert_post具有自定义字段的另一个数据库

时间:2014-03-09 17:38:07

标签: database wordpress post insert

wp_insert_post,其中包含您要将内容传输到另一个数据库的命令,

我使用以下命令

<?php

require('wp-config.php');
$conn = mysql_connect($dbHost, $dbUser, $dbPass);
mysql_select_db($dbName, $conn);
mysql_query('set names utf8');
mysql_query("SET character_set_connection = 'UTF8'");
mysql_query("SET character_set_client = 'UTF8'");
mysql_query("SET character_set_results = 'UTF8'");
$results = mysql_query("SELECT * FROM idx_link LIMIT 0,100", $conn);

function permayap($deger) {

    $turkce = array("ş", "Ş", "ı", "(", ")", "'", "ü", "Ü", "ö", "Ö", "ç", "Ç", " ", "/", "*", "?", "ş", "Ş", "ı", "ğ", "Ğ", "İ", "ö", "Ö", "Ç", "ç", "ü", "Ü");

    $duzgun = array("s", "s", "i", "", "", "", "u", "u", "o", "o", "c", "c", "-", "-", "-", "", "s", "s", "i", "g", "g", "i", "o", "o", "c", "c", "u", "u");

    $deger = str_replace($turkce, $duzgun, $deger);

    $deger = preg_replace("@[^A-Za-z0-9-_]+@i", "", $deger);

    return $deger;
}

$i = 0;
while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) {
    $post = array();
    $post['ID'] = $row['link_id'];
    $post['post_name'] = permayap($row['title']);
    $post['post_title'] = $row['title'];
    $post['post_status'] = 'publish';
    $post['post_type'] = 'post';
    $post['post_author'] = '1';
    $post['ping_status'] = 'open';
    $post['post_excerpt'] = '';
    $post['comment_status'] = 'open';
    $post['post_category'] = array($row['category_id']);
    $post['tags_input'] = $row['keywords'];
    $post['tax_input'] = array("sehir" => $row['sehir']);
    add_post_meta($post_id, 'telefon', '' . $row['telefon'] . '', true);
    $posts[$i] = $post;
    $i++;
}

mysql_free_result($results);
mysql_close($conn);

require('wp-load.php');

foreach ($posts as $post) {
    wp_insert_post($post);
}
?>

命令工作正常,但没有添加到wordpress数据库,你能帮我解决这个问题吗。

0 个答案:

没有答案