Über einen Filter und ein Hidden-Field können Objektnummer und -titel in CF7 Formularen ausgegeben werden:
/**
* [immonex OpenImmo2WP/Kickstart + Contact Form 7 (CF7)] Custom Mail Tag zum
* Einbinden von Immobilientitel und Objektnummer ergänzen.
*
* Formular: [hidden inx-property default:shortcode_attr]
*
* E-Mail / Nachrichtentext: [inx-property]
*/
add_filter( 'shortcode_atts_wpcf7', 'mysite_custom_shortcode_atts_wpcf7_filter', 10, 3 );
function mysite_custom_shortcode_atts_wpcf7_filter( $out, $pairs, $atts ) {
$post_id = apply_filters( 'inx_current_property_post_id', 0 );
if ( ! $post_id ) {
return $out;
}
$property_post = get_post( $post_id );
if ( ! $property_post ) {
return $out;
}
$my_attr = 'inx-property';
$custom_id = get_post_meta( $post_id, '_inx_property_id', true );
$out[ $my_attr ] = $property_post->post_title . ( $custom_id ? " ($custom_id)" : '' );
return $out;
} // mysite_custom_shortcode_atts_wpcf7_filter
Im Formular wird ein Hidden-Feld per Shortcode eingebunden:
[hidden inx-property default:shortcode_attr]Die Einbindung im Feld Nachrichtentext (Tab E-Mail) erfolgt mit folgendem Code:
[inx-property]