Getting the correct value for a post
I’ve added correct indenting to your question, which should make the problem more obvious. The problem is that you meant: foreach ( $state as $state ) update_post_meta($post_id,’state’,$state->name); What you actually put is: foreach ( $state as $state ); update_post_meta($post_id,’state’,$state->name); Which expands to: foreach ( $state as $state ) { // do nothing } //insert post … Read more