Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active December 2, 2017 17:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shelob9/d0f619668df94d82d9114c9178c6dfb8 to your computer and use it in GitHub Desktop.
Save Shelob9/d0f619668df94d82d9114c9178c6dfb8 to your computer and use it in GitHub Desktop.
<?php
add_filter( 'caldera_forms_render_get_field', function( $field ) {
if( 'fld123456' == $field[ 'ID' ] ){
$field[ 'config' ][ 'default' ] = esc_url_raw( caldera_forms_get_current_url() );
}
return $field;
});
<?php
add_filter( 'caldera_forms_render_get_field', function( $field, $form ){
if( 'dropdown' == $field[ 'type'] && ! empty( $field[ 'config' ][ 'option' ] ) ){
//@TODO Change field name to the right user custom field
$meta = get_user_meta( get_current_user_id(), 'field_name', true );
if ( ! empty( $meta ) ) {
foreach ( $field[ 'config' ][ 'option' ] as $option => $args ) {
if ( $meta == $args[ 'value' ] ) {
$field[ 'config' ][ 'default' ] = $option;
}
}
}
}
return $field;
}, 10, 2);
<?php
add_filter( 'caldera_forms_render_get_field', function( $field ) {
if ( 'stores_in_pa' == $field[ 'slug' ] ) {
$stores = get_posts( array( 'post_type' => 'stores', 'meta_key' => 'state', 'meta_value' => 'PA' ) );
if ( ! empty( $stores ) ) {
foreach( $stores as $store ) {
$field[ 'config' ][ 'option' ][ $store->ID ] = array(
'value' => $store->ID,
'label' => $store->post_title
);
}
}
}
return $field;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment