Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

wp_insert_post with the command you want to transfer the contents to another database,

I use the following command

<?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);
}
?>

command is working correctly, but does not add to the wordpress database, can you help me with this thank you.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.