AdvertCN - 广告中国

 找回密码
 立即注册

QQ登录

只需一步,快速开始

PropellerAds
Google-Bing-Mediago-Criteo开户
⚡️按条S5代理⚡️静态⚡️独享⚡️5G广告专用虚拟卡/U充值/高返点皇家代理IP⚡️#1性价比⚡️
Mediabuy⚡️玩家开户首选【鲁班跨境通-自助充值转账】FB/GG/TT❤️官方免费开户Affiliate 全媒体流量资源⚡️
Taboola/Outbrain /Bing⚡️一级代理开户投流-7*24h❤️人工在线【官方】❤️搜索套利买量投流开户独立站⚡️开户投放
⚡️AdsPower:安全不封号,高效自动化Google FB TK游戏代投⚡️E.PN 虚拟卡⚡️BINOM TRACKER 60% OFF!
比Adplexity还好用的Spy工具ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理虚拟信用卡+独立站收款
全球虚拟卡, 支持U充值Facebook 批量上广告尤里改 - FB 稳定投放免费黑五教程(持续更新、欢迎交流)
FB 三不限源头 - 自助下户充值转款各种主页、账单户、BM户(优势)IPCola原生住宅IP⚡️$1.8/条双ISPFB资源,账单户,分享户,国内一手
TK加白户/二解户/FB海外户/GG老户海外CL企业户源头最大欧洲Nutra网盟BA找量 FB高权重耐操个号⚡️稳定过审
GG,FB,TK, 欧美源头, 欢迎合作❤️FB企业户海外户,授信户,TK加白户联盟收款/海外资金下发/服贸结汇域名防红⚠斗篷工具/可试用3天
⚡️Spend.net — 美元卡仅需$0⚡️广告位出租8500万高质量住宅IP,助力各种需求虚拟卡返佣1%,国内持牌机构
查看: 8114|回复: 3

[原创教程] wordpress 调用函数更新文章 多站管理 Post操作就可以了

[复制链接]

14

主题

39

广告币

219

积分

初级会员

Rank: 2

积分
219

社区QQ达人

发表于 2013-2-25 14:36:05 | 显示全部楼层 |阅读模式
Binom_AdvertCN
本帖最后由 finder 于 2014-12-28 15:13 编辑 8 L; P& v& d0 g4 i' ?

3 f" r9 r0 v, v" ^直接插入数据库 字段太多混乱 同时MYSQL 还得支持外连 很多虚拟空间不支持2 G/ ?/ x. o0 T8 Q

. e6 w9 H2 T3 I  O* ?我们可以利用 wordpress 自带的函数 wp_insert_post 调用插入一个新的文章  如果你采集的文章直接使用一个post操作就可以了- @$ g4 C, Y, O& u9 @. `

# \, F! A2 \/ |4 w, W方便实用 简单 何乐而不用呢
  1. 7 X# ?4 k0 P. n0 U4 e  S* d  L
  2. <?php1 b4 b6 b- b" D) r" l
  3. 0 E, N! h% B/ W. w6 S  {$ Z
  4. define( 'ABSPATH', dirname(__FILE__) . '/' );
    ' z" R+ G. D! L% O
  5. require_once( ABSPATH . 'wp-config.php' );
    $ f* U6 u3 A$ t- P
  6. require_once( ABSPATH . 'wp-settings.php' );
    5 J+ ?. F" i2 p  U6 N# e0 ~5 n
  7. require_once( ABSPATH . 'wp-includes/class-wp.php' );) m% @8 s8 u) T# Z1 B
  8. require_once( ABSPATH . 'wp-includes/functions.php' );
    ' E# p+ B: U! T. r+ J! u6 P
  9. require_once( ABSPATH . 'wp-includes/plugin.php' );6 Y& B) b6 J, G! t, J
  10. $title = $_POST["title"];$ f( I0 P$ P- z& o5 n3 K' V
  11. $content = $_POST["content"];
    ) T( N7 S) }  ?% O
  12. $tags = explode("_",$_POST["tags"]);
    ( x* h& S- X! g" G$ b2 P0 D
  13. $cate = $_POST["cate"];
    , w4 k0 V6 ~- S( F3 {  T( d
  14. //print_r $tags;3 a" o, L/ E/ A
  15. //
    4 s, H4 O+ M8 c6 T# ]2 o- n6 f
  16. //
    - y" ^6 a# V, ~1 ~8 q5 w. `
  17. $wp = new WP();
    $ `! S7 |( t' u3 B1 w# L1 ?, R6 O# O
  18. $wp->main();
    " U+ a( ~* P% H3 n6 o& T2 ~: J
  19. //
    " y7 h/ Y5 v0 h
  20. $my_post = array();5 ?0 _$ R6 R  t& t# K$ E$ ^
  21. $my_post['post_title'] = $title;3 {7 ~7 ?1 O& h- S- X" W
  22. $my_post['post_content'] = $content;/ r8 [2 l4 {( s& o9 G
  23. $my_post['post_status'] = 'publish';
    2 o7 t/ c: i9 R8 u& _. w
  24. $my_post['post_author'] = 1;
    8 K% ]* V% t) q" v
  25. $my_post['post_category'] = array($cate);- S/ |& P( R% M3 b' a
  26. $my_post['tags_input'] = $tags;! A" W) [$ v$ C# E% n% j+ g+ k2 U3 z3 l
  27. //$my_post['tags_input'] = array('tag1', 'tag2');
    0 V+ J& r2 O% S# X
  28. //$my_post['post_status'] = 'future';, F4 N2 U0 T! e* V! K
  29. ////$my_post['post_date'] = '2010-07-04 16:20:03';
    ' Y! m) k9 X; Y
  30. 3 g5 p& [, n, [
  31. // Insert the post into the database
    ' b+ a0 D! }; z/ F1 n' G6 @5 M
  32. $ret = wp_insert_post( $my_post );
    ' Y( v3 S# p' W1 O
  33. echo $ret;
    ) d- r! e, ?  t" Y7 X2 J
  34. ?>. g: k4 D7 \$ [$ _
复制代码
下面是更带更新图片版因为有些网站屏蔽了盗链接 小气
  1. 2 i9 S# d. w+ L- h$ C8 u2 A1 O/ w1 z
  2. <?php4 d7 s, }: l: O8 c  [2 |; \
  3. define( 'ABSPATH', dirname(__FILE__) . '/' );, N8 c1 O) u! P
  4. require_once( ABSPATH . 'wp-config.php' );
    6 x; J1 h3 S* N2 Z  `! B( X
  5. require_once( ABSPATH . 'wp-settings.php' );6 ^: d$ E" P& v/ z1 _7 h
  6. require_once( ABSPATH . 'wp-includes/class-wp.php' );5 g2 b4 Y& [* U6 E! y) K- B
  7. require_once( ABSPATH . 'wp-includes/functions.php' );
    $ W: g# v4 r/ G* d* x. M& G! z3 K! N
  8. require_once( ABSPATH . 'wp-includes/plugin.php' );7 Z5 K8 |/ l& C0 R8 e. U' s7 v& u
  9. $pic_name = $_POST["pic_name"];- s9 g9 K9 I2 W5 ]9 I% x3 N  C2 M
  10. $pic = $_POST["pic"];! N. K, w4 L+ U1 p
  11. if($pic != "" && $pic_name != "")
    & I: j$ `$ W3 f( F, T( u" ]
  12. {
    , w  F( f/ V: _5 y- I" V
  13. $path = "images/";
      H. E1 A" U% C+ g& ~- u
  14. $pic_name = $path.$pic_name;  P+ \) [# v) N' T3 \
  15. echo $pic_name;% H4 y) [+ D5 v+ m/ N* S
  16. echo "||";, }8 j5 M0 Y5 U, Z7 @, y# W
  17. error_reporting(0);
    1 E0 D. `5 P; v1 m
  18. mkdir("images");5 N  \$ Y* _$ S7 L; f
  19. $handle = fopen($pic_name, 'w');
    9 b/ C: }) g3 d5 L
  20. echo fwrite($handle,file_get_contents($pic));
    . Y- `  e/ T; [) f3 s
  21. }2 K5 L& i# e2 e/ l  _# n

  22. ( `3 x* N0 ?6 F- M" F5 A
  23. $title = $_POST["title"];
    * p" N, Q/ ^6 J: }
  24. $content = $_POST["content"];- J2 r3 O$ ]" l' ~
  25. $tags = explode("_",$_POST["tags"]);
    1 n# A7 v, {" y1 ?, J3 J+ Y
  26. $cate = $_POST["cate"];; @$ P- n) o9 x  m; K$ J: \: _; \/ u
  27. //print_r $tags;
      B) {4 u# T# @9 b8 u
  28. /// r# M! a! W9 c: h; Q
  29. //
    + L8 b, U' ^! ~+ e* v
  30. $wp = new WP();
    1 M. w0 o& B* c' |
  31. $wp->main();
    " M$ k2 A7 ?4 g: J# ?% U: \
  32. //
    . O0 W5 S9 l2 W% N% h  _
  33. $my_post = array();" i: Z, h! Z! q7 A) X
  34. $my_post['post_title'] = $title;
    + Y2 h6 m, A8 ~4 j& R$ L$ f
  35. $my_post['post_content'] = $content;
    " E( \/ g8 t2 M9 ]" E6 [. b$ L
  36. $my_post['post_status'] = 'publish';
    ; m8 p) ~# o4 Y
  37. $my_post['post_author'] = 1;& Z$ i1 @' [% q5 z
  38. $my_post['post_category'] = array($cate);, V1 L) M; |1 j% D
  39. $my_post['tags_input'] = $tags;9 U. s" @) b, L4 d
  40. //$my_post['tags_input'] = array('tag1', 'tag2');0 g# Q: G: E: d2 ]$ K
  41. //$my_post['post_status'] = 'future';
    ) q- Y! f, u( d3 `
  42. ////$my_post['post_date'] = '2010-07-04 16:20:03';' ^( u4 r/ R9 ]0 c8 ^- ^
  43. + P$ _, m$ \" D5 z& ]# g
  44. // Insert the post into the database
    7 E# ^3 R4 o2 ]( w* L8 d2 \' s
  45. $ret = wp_insert_post( $my_post );
    & _1 k, U; Y0 g
  46. echo $ret;
    ' y. Y  W% k3 @/ h* c
  47. ?>
    9 P& @' x7 v: i
复制代码
我自己写的
/ E/ w1 N3 h0 C6 z; r插入效果看图 不看广告看效果 已经测试过有需要的 拿去

评分

参与人数 4广告币 +6 收起 理由
helloworld + 1 赞一个!
mj23zyb + 2 经验不错!
suyu8776 + 2 很给力!刚想自己写一个呢
左庶长 + 1 很给力!期待更多分享:)

查看全部评分

相关帖子
回复

使用道具 举报

54

主题

9

广告币

6010

积分

禁止访问

积分
6010
发表于 2013-2-25 19:12:29 | 显示全部楼层
火车头的wp免登陆接口就是利用wp_insert_post,用哈默的接口相对强大些
回复 支持 反对

使用道具 举报

21

主题

679

广告币

894

积分

中级会员

Rank: 3Rank: 3

积分
894

社区QQ达人

发表于 2013-2-25 20:33:59 | 显示全部楼层
用xmlrpc不是更好吗
回复 支持 反对

使用道具 举报

15

主题

598

广告币

565

积分

中级会员

Rank: 3Rank: 3

积分
565
发表于 2015-3-3 14:05:49 | 显示全部楼层
楼主辛苦了!~~
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们|联系我们|DMCA|广告服务|小黑屋|手机版|Archiver|Github|网站地图|AdvertCN

GMT+8, 2026-7-3 19:48 , Processed in 0.049295 second(s), 14 queries , Gzip On, MemCache On.

Copyright © 2001-2023, AdvertCN

Proudly Operating in Hong Kong.

快速回复 返回顶部 返回列表