Created
September 21, 2021 09:46
-
-
Save GauravKhupse/012e2291931bc4c5618f1a468cc8c06e to your computer and use it in GitHub Desktop.
aluminiOf repeater field in the person schema
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'after_setup_theme', 'add_my_custom_meta_field' ); | |
function add_my_custom_meta_field() { | |
add_filter( 'wp_schema_pro_schema_meta_fields', 'my_extra_schema_field' ); | |
add_filter( 'wp_schema_pro_schema_person', 'my_extra_schema_field_mapping', 10, 3 ); | |
} | |
/** | |
* Add fields for mapping. | |
* | |
* @param array $fields Mapping fields array. | |
* @return array | |
*/ | |
function my_extra_schema_field( $fields ) { | |
$fields['bsf-aiosrs-person']['subkeys']['alumniOf'] = array( | |
'label' => esc_html__( 'Alumni Of', 'wp-schema-pro' ), | |
'type' => 'repeater', | |
'fields' => array( | |
'alumini' => array( | |
'label' => esc_html__( 'Alumni Of', 'wp-schema-pro' ), | |
'type' => 'text', | |
'default' => 'create-field', | |
), | |
), | |
); | |
return $fields; | |
} | |
/** | |
* Mapping extra field for schema markup. | |
* | |
* @param array $schema Schema array. | |
* @param array $data Mapping fields array. | |
* @return array | |
*/ | |
function my_extra_schema_field_mapping( $schema, $data, $post ) { | |
if (isset( $data['alumniOf'] ) && ! empty( $data['alumniOf'] ) ) { | |
foreach ( $data['alumniOf'] as $key => $value ) { | |
$schema['alumniOf'][ $key ]['@type'] = 'Organization'; | |
if ( isset( $value['alumini'] ) && ! empty( $value['alumini'] ) ) { | |
if ( isset( $value['alumini'] ) && ! empty( $value['alumini'] ) ) { | |
$schema['alumniOf'][ $key ]['name'] = wp_strip_all_tags( $value['alumini'] ); | |
} | |
} | |
} | |
} | |
return $schema; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment