Skip to content

Snippet: Adding a First & Last Name Field for Staff Members

By default the theme uses the title for the names of your staff members. However, if you need to sort your staff members by last name or if you want to do custom queries based on first or last names then you may want to add additional fields for this.

add_filter( 'wpex_metabox_array', function( $array ) {

	// Make sure staff tab exists in arrray
	if ( isset( $array['staff'] ) ) {

		// Add First name to staff
		$array['staff']['settings']['first_name'] = array(
			'title'         => __( 'First Name', 'total' ),
			'description'   => __( 'Field description', 'total' ),
			'id'            => 'wpex_first_name', // Custom field ID used to retrive via get_post_meta
			'type'          => 'text',
		);

		// Add Last name to staff
		$array['staff']['settings']['last_name'] = array(
			'title'         => __( 'Last Name', 'total' ),
			'description'   => __( 'Field description', 'total' ),
			'id'            => 'wpex_last_name', // Custom field ID used to retrive via get_post_meta
			'type'          => 'text',
		);

	}

	// Return meta array
	return $array;

}, 40 );
All PHP snippets should be added via child theme's functions.php file or via a plugin. We recommend Code Snippets (100% Free) or WPCode (sponsored)
Back To Top