wordpress 调用函数更新文章

直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持

我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章  如果你采集的文章直接使用一个post操作就可以了

方便实用 简单 何乐而不用呢

[php]

<?php

define( ‘ABSPATH’, dirname(__FILE__) . ‘/’ );
require_once( ABSPATH . ‘wp-config.php’ );
require_once( ABSPATH . ‘wp-settings.php’ );
require_once( ABSPATH . ‘wp-includes/class-wp.php’ );
require_once( ABSPATH . ‘wp-includes/functions.php’ );
require_once( ABSPATH . ‘wp-includes/plugin.php’ );
$title = $_POST["title"];
$content = $_POST["content"];
$tags = explode("_",$_POST["tags"]);
$cate = $_POST["cate"];
//print_r $tags;
//
//
$wp = new WP();
$wp->main();
//
$my_post = array();
$my_post[‘post_title’] = $title;
$my_post[‘post_content’] = $content;
$my_post[‘post_status’] = ‘publish’;
$my_post[‘post_author’] = 1;
$my_post[‘post_category’] = array($cate);
$my_post[‘tags_input’] = $tags;
//$my_post[‘tags_input’] = array(‘tag1’, ‘tag2’);
//$my_post[‘post_status’] = ‘future’;
////$my_post[‘post_date’] = ‘2010-07-04 16:20:03’;

// Insert the post into the database
$ret = wp_insert_post( $my_post );
echo $ret;
?>
[/php]

下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
[php]
<?php
define( ‘ABSPATH’, dirname(__FILE__) . ‘/’ );
require_once( ABSPATH . ‘wp-config.php’ );
require_once( ABSPATH . ‘wp-settings.php’ );
require_once( ABSPATH . ‘wp-includes/class-wp.php’ );
require_once( ABSPATH . ‘wp-includes/functions.php’ );
require_once( ABSPATH . ‘wp-includes/plugin.php’ );
$pic_name = $_POST["pic_name"];
$pic = $_POST["pic"];
if($pic != "" && $pic_name != "")
{
$path = "images/";
$pic_name = $path.$pic_name;
echo $pic_name;
echo "||";
error_reporting(0);
mkdir("images");
$handle = fopen($pic_name, ‘w’);
echo fwrite($handle,file_get_contents($pic));
}

$title = $_POST["title"];
$content = $_POST["content"];
$tags = explode("_",$_POST["tags"]);
$cate = $_POST["cate"];
//print_r $tags;
//
//
$wp = new WP();
$wp->main();
//
$my_post = array();
$my_post[‘post_title’] = $title;
$my_post[‘post_content’] = $content;
$my_post[‘post_status’] = ‘publish’;
$my_post[‘post_author’] = 1;
$my_post[‘post_category’] = array($cate);
$my_post[‘tags_input’] = $tags;
//$my_post[‘tags_input’] = array(‘tag1’, ‘tag2’);
//$my_post[‘post_status’] = ‘future’;
////$my_post[‘post_date’] = ‘2010-07-04 16:20:03’;

// Insert the post into the database
$ret = wp_insert_post( $my_post );
echo $ret;
?>
[/php]

插入效果看图 不看广告看效果

发表评论