Title: custom fields
Last modified: August 22, 2016

---

# custom fields

 *  Resolved [argate7](https://wordpress.org/support/users/argate7/)
 * (@argate7)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-fields-142/)
 * Hi,
 * I’ve created 2 columns in wp_posts, post_language and post_project, because i
   want to view certain posts and media according the session that i passed from
   another site to the wordpress.
 * Now, i’ve got a problem in media section. I’m trying to insert a media and give
   the 2 columns values but i cannot achieve this.
    In my plugin i have this one..
 *     ```
       function modify_columns( $post_id ) {
       	remove_action( 'save_post', 'modify_columns' );
       	wp_update_post( array( 'ID' => $post_id, 'post_project' => "".$_SESSION['project']."", 'post_language' => "".$_SESSION['language']."" ) );
       	add_action( 'save_post', 'modify_columns' );
       }
       ```
   
 * add_action(‘save_post’, ‘modify_columns’);
 * function wp_insert_post_data_filter( $data, $postarr ) {
    $data[‘post_project’]
   = $_SESSION[‘project’]; $data[‘post_language’] = $_SESSION[‘language’]; return
   $data; }
 * add_filter( ‘wp_insert_post_data’, ‘wp_insert_post_data_filter’, 10, 2 );
 *     ```
       This is in order to pass the values to the 2 columns. This works like a charm in posts and pages section. But in media there is a problem.
   
       Is there anyone that can help me resolve this one?
   
       I forgot to mention that if i placed this code
       ```
   
 * $data[‘post_project’] = $_SESSION[‘project’];
    $data[‘post_language’] = $_SESSION[‘
   language’];` in post.php in wp_insert_post function before if ( ‘attachment’ 
   === $post_type ) { it works, but i don’t want to change the core files because
   if i update the wp, i will lose all my changes.
 * Please help me resolve this!
 * Thank you in advance!

Viewing 1 replies (of 1 total)

 *  Thread Starter [argate7](https://wordpress.org/support/users/argate7/)
 * (@argate7)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/custom-fields-142/#post-5362044)
 * I resolved this by using the following
 *     ```
       global $wpdb;
            $wpdb->query(update...
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘custom fields’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [wp_posts](https://wordpress.org/support/topic-tag/wp_posts/)

 * 1 reply
 * 1 participant
 * Last reply from: [argate7](https://wordpress.org/support/users/argate7/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/custom-fields-142/#post-5362044)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
