php - how to add posts with image programmatically in wordpress -


This code requires

  to add a post to the program in WordPress (Dynom) (__ file__). '/wp-load.php'); Global $ user_ID; $ New_post = array ('post_title' = & gt; 'Table Tennis',' Post_ content '= & gt;' Table Tennis or Ping-Pong is a game in which two or four players use a table tennis racket The back and back game is played on a hard disk divided into a net, except for the initial service, the players should be allowed to bowl only on one side of their side of the table, so that it can be bounced in the opposite direction. not Fails to return the ball within the yama, then the points are made. ',' Post_States' = & gt; 'Publish', 'Post_data' = & gt; Date ('YMD HH: I: S' ), 'Post_yyther' = & gt; $ User_ID, 'Post_type' = & gt; 'Post', 'Postgate' => Array (2),); $ Post_id = wp_insert_post ($ new_post);   

How to add the image to the post?

I am new to WordPress, thanks in advance ..

This wordpress Will upload the file and then put it on post as a special image. $ wp_filetype = wp_check_filetype ($ filename, null); $ Attachment = array ('post_mime_type' = & gt; $ wp_filetype ['type'], 'post_title' = & gt; $ filename, 'post_content' = & gt; '', 'post_status' = & gt; 'inheritance' ); $ Attach_id = wp_inert_attachment ($ attachment, $ thumbnail, $ post_id); // You must first include / include the image.php file for the wp_generate_attachment_metadata () function to include.online (abaspace '.wp-admin / include / image.php'); $ Attach_data = wp_generate_attachment_metadata ($ enclosed_id, $ thumbnail); Wp_update_attachment_metadata ($ attach_id, $ attach_data); // add_post_meta ($ post_id, '_thumbnail_id', $ attach_id) Add a featured image to post;

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -