How to save an array with one metakey in postmeta?
-
I have an array saved in postmata, each array key become a metakey. I want to change the code to save the whole array with one metakey. How to do that?
Here’s my current code:$poddata = Array( 'pod_id' => $this->pod_id, 'url' => $this->url, 'name' => $this->name, 'description' => $this->description, 'service' => $this->service, 'status' =>$this->status, 'price' => $this->price ); foreach ( $poddata as $k => $v ){ if ( get_post_meta( $this->id, $k ) == '' ) add_post_meta( $this->id, $meta_box, $v, true ); elseif ( $v != get_post_meta( $this->id, $k, true ) ) update_post_meta( $this->id, $k, $v ); elseif ( $v == '' ) delete_post_meta( $this->id, $k, get_post_meta( $this->id, $k, true ) ); }
I tried
update_post_meta( $this->id, ‘pod’, $poddata );
It doesn’t work.
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to save an array with one metakey in postmeta?’ is closed to new replies.