最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Copying taxonomy term to custom field

programmeradmin2浏览0评论

I have a custom post type called "listing", and a custom taxonomy called "listing_state".

I'm using formidable to create posts. What I am trying to do is have two things happen when a user selects a state from the taxonomy drop down.

First, to set the taxonomy, which is what happens now. But then at the same time, also have this selected state get copied to a custom field called "state".

The end result should be a listing that is classified by state, but that also holds that state name in a custom field as well.

Any ideas? Thanks in advance for any help.

I have a custom post type called "listing", and a custom taxonomy called "listing_state".

I'm using formidable to create posts. What I am trying to do is have two things happen when a user selects a state from the taxonomy drop down.

First, to set the taxonomy, which is what happens now. But then at the same time, also have this selected state get copied to a custom field called "state".

The end result should be a listing that is classified by state, but that also holds that state name in a custom field as well.

Any ideas? Thanks in advance for any help.

Share Improve this question asked Sep 12, 2012 at 4:08 DanDan 212 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 0

Try hooking into 'save_post' action:

add_action( 'save_post', 'your_state_term_save' );

function your_state_term_save( $post_id ){

    // Bail if we're doing an auto save
    if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;

    //check if they selected your state term
    $state = isset($_POST['tax_input_field_name']) ? $_POST['tax_input_field_name'] : ''; //make sure of what the input name is here...

    //insert post meta
    update_post_meta($post_id,'state',$state);
}

This works by waiting till the post is saved and grabbing the taxonomy term right out of the $_POST vairable.

发布评论

评论列表(0)

  1. 暂无评论