The function you are looking for is wp_update_post()
.
You would want to have your posts which you want to update, then set up a loop to update each one individually.
// However you get your posts, ID's, etc.
$posts = get_posts( array( 'post_type' => 'post' ) );
for ( $posts as $post ) {
wp_update_post( array( 'ID' => $post->ID, 'post_parent' => 8 ) );
}
For a generic SQL call, look at the $wpdb
object, and it's prepare
and query
functions:
global $wpdb;
$query = $wpdb->prepare( 'UPDATE wp_posts SET post_parent = %d WHERE post_type = %s', 8, 'my-post-type' );
$wpdb->query( $query );
You could also look into $wpdb->update
- it may suit your needs better in the future.