adding post and postmeta using custom php file?
-
hello, i’m trying to add posts and postmeta using a custom php file that i have created and uploaded to my server, i found some pages that shows the code that i need to use, but i have tried and didn’t work, this is the code that i’m using:
<?php require( 'my_domain/wordpress_root/wp-load.php'); $title_add="testing php post"; $content_add="<p align='justify'>just testing the add post using custom php</p>"; // Create post object $my_post = array( 'post_id' => 22; 'post_title' => $title_add, 'post_content' => $content_add, 'post_status' => 'publish', 'post_author' => 1, 'post_category' => array( 8,39 ) ); // Insert the post into the database wp_insert_post( $my_post ); add_post_meta(22,'_testing_post_meta_add','just text to let see if this is working') function add_post_meta( $post_id, $meta_key, $meta_value, $unique = false ) { // Make sure meta is added to the post, not a revision. if ( $the_post = wp_is_post_revision($post_id) ) $post_id = $the_post; return add_metadata('post', $post_id, $meta_key, $meta_value, $unique); } ?>
on my server this is not working, will be very useful if someone point to my to a working php code sample to make this working.
please take in consideration that i’m not a programmer, but i have some basic knowledge about php.
thank you in advance for all your help.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘adding post and postmeta using custom php file?’ is closed to new replies.