Top Poster
#1 ramon fincken 399
#2 Site admin 3
#3 Ber|Art 2
#4 braddmark 1
#5 accentmedia 1
#6 Xarzu 1
#7 pEcosespedex 1
#8 khadish 1
#9 moxxx 1
#10 nistelrock 1
[wordpress][solution] How to code (API) a new post or page insert ..



Rating : 4 / 5

 
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> CMS-ses (Joomla, WordPress, etc..)
Beta
Want to be notified by email when this topic gets a reply?  
View previous topic :: View next topic  
Author Message
ramon fincken
Site's programmer

Get a free globally recognized avatar
It's free!


Joined: 03 Aug 2007
Posts: 399
Location: A'dam/Diemen, The Netherlands

PostPosted: Mon Sep 28, 2009 8:45 pm    Post subject: [wordpress][solution] How to code (API) a new post or page insert .. Reply with quote

How to write your own code to insert a post or a page? Eazy! just use wp_insert_post() Smile

Here you go:
http://codex.wordpress.org/Function_Ref...nsert_post
Warning: do not use $my_post['post_author'] = 1; as stated on the codex page, use 2 for the main admin.


Code:
// Create post object
  $my_post = array();
  $my_post['post_title'] = 'My post';
  $my_post['post_content'] = 'This is my post.';
  $my_post['post_status'] = 'publish';
  $my_post['post_author'] = 2;
  $my_post['post_category'] = array(8,39);

// Insert the post into the database
  wp_insert_post( $my_post );

Code:
$defaults = array(
  'post_status' => 'draft',
  'post_type' => 'post',
  'post_author' => $user_ID,
  'ping_status' => get_option('default_ping_status'),
  'post_parent' => 0,
  'menu_order' => 0,
  'to_ping' =>  '',
  'pinged' => '',
  'post_password' => '',
  'guid' => '',
  'post_content_filtered' => '',
  'post_excerpt' => ''
);
Back to top
View user's profile Send private message Visit poster's website
Google adsense
Advertisement





PostPosted: Mon Sep 28, 2009 8:45 pm    Post subject: [wordpress][solution] How to code (API) a new post or page insert ..

Advertisement
Back to top
GravityForms
Advertisement





PostPosted: Mon Sep 28, 2009 8:45 pm    Post subject: [wordpress][solution] How to code (API) a new post or page insert ..

Advertisement
Gravity Forms Plugin for WordPress
Back to top
Post new topic   Reply to topic    Ramonfincken.com Forum Index -> CMS-ses (Joomla, WordPress, etc..) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
General forums
The world of freelance
Programming
Other projects
Poll
I love gifts

Yes goodies and presents! [3]
No but I love polls ! [1]

Related google ads