• Resolved Thodoris

    (@peltho)


    I extent the build in post post_type and add some custom fields. I want set the values of a custom field as tags.
    I write a function and I use using pod() to get custom field values and wp_set_object_terms() to set tags, I call this function with save_post filter.
    The problem is when I create new post and save it for first time I receive error “Call to a member function field() on bool”
    I try to use pods_api_post_save_pod_item_post filter than save post but without success
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Thodoris

    (@peltho)

    Finally pods_api_post_save_pod_item_post works

    Here is a sample from the code

    add_filter( 'pods_api_pre_save_pod_item_post', 'save_cats_and_tags', 10, 2);
    function save_cats_and_tags( $pieces, $is_new_item ) {
    	// get tags
    	$fields = array(
    		$pieces[ 'fields' ][ 'tags_field' ][ 'value' ],
    	);
    	$tags = array();
    	foreach ( $fields as $field ) {
    		foreach ( $field as $id ) {
    			if ( !in_array( $id, $tags ) ) {
    				$tags [] = intval ( $id );
    			}
    		}
    	}
    	// save tags
    	if ( !empty( $tags ) ) {
    		sort($tags);
    	}
    	wp_set_object_terms( get_the_ID() , $tags, post_tag );
    }
    Plugin Author Jory Hogeveen

    (@keraweb)

    Hello @peltho

    Good to hear you’ve solved it, thanks for sharing!

    Cheers, Jory

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Set post tags from a POD custom field field value’ is closed to new replies.