• Hello!
    When I select the fied to append to an user field type it shows “array”, can you help?

    It seemns that the user field type returns an array that looks like this:

    [ID] => 6
        [user_firstname] => John
        [user_lastname] => Doe
        [nickname] => johndoe
        [user_nicename] => johndoe
        [display_name] => John Doe
        [user_email] => [email protected]
        [user_url] => 
        [user_registered] => 2016-07-03 12:23:56
        [user_description] => 
        [user_avatar] =>

    Thank you!

Viewing 1 replies (of 1 total)
  • Plugin Author David Baumwald

    (@davidbaumwald)

    Hello @adrianspk! What I think would be best is to directly filter the field output after the generic output is compiled. The “User” field type has three output value types: array, object, or ID. Looks like you’re using the default of array. Using apply_filters( 'de/acfpoftao/format_post_title', $title, $post, $field, $post_id ) will work like this…

    function de_filter_post_object_add_on_output( $title, $post ) {
    		$append_field = get_option( 'de_acfpoftao_append_field' );
    		$user         = get_field( $append_field, absint( $post->ID ) );	
    
    		if ( ! $user || empty( $append_field_value ) ) {
    			return $title;
    		}
    
    		$append_field_value = $user['display_name'];
    		
    		$format = apply_filters( 'de/acfpoftao/append_field_data_format', get_option( 'de_acfpoftao_append_field_format' ) );
    
    		switch ( true ) {
    			case preg_match( "/^separator::(.*)/", $format, $matches ):
    				$title .= ' &' . $matches[1] . '; ' . $append_field_value;
    				break;
    			case preg_match( "/^wrap::(.*)/", $format, $matches ):
    				$title .= ' &l' . $matches[1] . ';' . $append_field_value . '&r' . $matches[1] . ';';
    				break;
    			default:
    				$title .= ' (' . $append_field_value .  ')';
    				break;
    		}
    
    		return $title;
    	}
    
    	add_filter( 'de/acfpoftao/format_post_title', 'de_filter_post_object_add_on_output', 10, 2 );
    

    Note: I’ve not tested this code, but in theory it should work.

Viewing 1 replies (of 1 total)
  • The topic ‘Post type user error’ is closed to new replies.