custom page in php to update multiple posts
-
Hello,
The situation:
– i have installed a wordpress which works well at this domain: https://www.custom-domain.com
– i would like to add a page, for example https://www.custom-domain.com/up.php, which update some posts on loading.As it is temporally and i get hundreds posts to update, i don’t want to use the back-office and neither an import plugin. I get the field to update as a plain text list. An additional difficulty, some filed are ACF ones and not yet fill in the post (the row doesn’t exist in the wp_postmeta table).
So i create up.php in the root WP directory like that:
<?php require( dirname( __FILE__ ) . '/wp-blog-header.php' ); $my_post = array( array( 'ID' => 9924, 'chapo' => 'Lorem Ipsum', '_chapo' => 'field_5458ff1e418c7', // ACF Field ), array( 'ID' => 12039, 'chapo' => 'Zombie Ipsum', '_chapo' => 'field_5458ff1e418c7', ), ); function update($post_list) { foreach ( $post_list as $post ) { $post_ID = $post['ID']; $post_title = get_the_title($post_ID); wp_update_post( $post ); // update_post_meta( $post_ID, 'chapo', $post['chapo'] ); printf ("%u - %s ok<br/>",$post_ID,$post_title); } }; update($my_post); ?>
The script seems to works but the wp_update_post doesn’t. My custom field is not update.
Could it be a problem with the WP function? With the position of the page?
Could it be a problem of right?
Do i have to change the way of doing this?Thank you in advance for any help.
jbo
- The topic ‘custom page in php to update multiple posts’ is closed to new replies.