Forum Replies Created
-
AuthorPosts
-
February 12, 2024 at 11:35 PM in reply to: Feature Request: allow duplicating cloneable fields/groups #44552
leebazCDS
ParticipantIs there any update on this feature? It would be very useful indeed!
leebazCDS
ParticipantThanks, I'm only really interested in the lat and long values for the map location, I don't really need things like postcode or street name.
The map does seem to be working, it's just that pop-up box that makes it a bit annoying.
leebazCDS
ParticipantI'm using two fields: lat and long for those. And yes, I can see that they are connected to the map pin - if I move the pin their values update.
Should I make the field id address_lat and address_lng ?
leebazCDS
ParticipantOK thanks, I think I got confused by 'geometry' as a value that is stored for lat-long.
I have made a short screen recording of the pop-up issue. Maybe it's only when pasting a value into the lat or long field?
The recording is in this folder:
movie FolderAlso, I'm still struggling to get a custom select function to save to the database, as per this thread. I marked it as resoled accidentally, but it's not working yet and I'd really appreciate some guidance!
leebazCDS
ParticipantImages can be seen here:
Image FolderJanuary 24, 2024 at 11:10 PM in reply to: ✅Add Dropdown select of saved data using functions.php #44379leebazCDS
ParticipantHi,
I've tested with the simplified version and it works as expected; the values are saved and I'm able to retrieve them on the front end.
Lee
January 23, 2024 at 11:30 PM in reply to: ✅Custom field SELECT is not saving or displaying value. #44373leebazCDS
ParticipantI'm having the same problem with a callback function to populate a Select list dynamically from values stored in another custom field group within the same post.
Did you resolve this?January 23, 2024 at 10:59 PM in reply to: ✅Add Dropdown select of saved data using functions.php #44371leebazCDS
ParticipantCan anyone help me with getting the dynamically populated values to save?
January 19, 2024 at 5:49 PM in reply to: ✅Add Dropdown select of saved data using functions.php #44353leebazCDS
ParticipantWhile I can see my options in the select dropdown, the chosen item is not saved when the post is updated.
I tested with this simplified version:
function populate_my_select_field() { return [ 'option1' => 'Option 1', 'option2' => 'Option 2', ]; }But when I populate using fields from the post, the select box is refreshed each time. How do I get it to commit? One way would be to check through the entries each time in the function and compare to the current value of the dropdown... but is there a more efficient way?
function populate_my_select_field() { return [ 'option1' => 'Option 1', 'option2' => 'Option 2', ]; }And the dynamically populated version:
function populate_my_select_field() { $options = []; $post_id = null; if (is_admin()) { $post_id = $_GET['post'] ?? get_the_ID(); } if ($post_id) { // Define the groups and their corresponding prefixes $group_ids = [ 'group_j7gfnvh6y4t' => 'Anem', // Anemometers 'vanes' => 'Vane', // Wind Vanes 'miscelaneou' => '' // Miscellaneous ]; foreach ($group_ids as $group_id => $prefix) { $groups = rwmb_meta($group_id, '', $post_id); // Check if $groups is an array before iterating if (is_array($groups)) { foreach ($groups as $group) { $height = $group['height'] ?? ''; $serial_no = isset($group['serial_no']) ? trim($group['serial_no']) : ''; // Trim the serial number $type = $group_id === 'miscelaneou' ? ($group['type'] ?? 'Unknown') : ''; if ($height && $serial_no) { // Construct a unique key and label for the option //$key = $group_id . '_' . $serial_no; //$label = ($prefix ?: $type) . " " . $height . "m, Serial No ". $serial_no; $key = $serial_no; $label = $serial_no; $options[$key] = $label; } } } } } return $options; }January 19, 2024 at 12:02 AM in reply to: ✅Add Dropdown select of saved data using functions.php #44349leebazCDS
Participantfound my way through this, in case anyone else needs it:
function populate_my_select_field() { //global $post; $options = []; $post_id = null; // Check if we are in the admin area and a post object exists if (is_admin()) { $post_id = $_GET['post'] ?? get_the_ID(); error_log('Current post ID: ' . $post_id); // Fetch the meta values from the specified group for the current post $groups = rwmb_meta('group_j7gfnvh6y4t', '', $post_id); error_log(print_r($groups, true)); foreach ($groups as $group) { // Assuming 'height' and 'serial_no' are keys in your group $height = $group['height'] ?? ''; $serial_no = $group['serial_no'] ?? ''; if ($height && $serial_no) { $key = $serial_no; // Using serial_no as the value $options[$key] = "Height: $height, Serial No: $serial_no"; } } } return $options; }January 18, 2024 at 10:37 PM in reply to: ✅Add Dropdown select of saved data using functions.php #44340leebazCDS
ParticipantI'm trying a different tack using the Select Advanced field and a callback function.
This is my function, but it's not populating the dropdown yet...function populate_my_select_field() { global $post; $options = []; // Check if we are in the admin area and a post object exists if (is_admin() && !empty($post)) { $post_id = $post->ID; // Fetch the meta values from the specified group for the current post $groups = rwmb_meta('group_j7gfnvh6y4t', '', $post_id); foreach ($groups as $group) { // Assuming 'height' and 'serial_no' are keys in your group $height = $group['height'] ?? ''; $serial_no = $group['serial_no'] ?? ''; if ($height && $serial_no) { $key = $serial_no; // Using serial_no as the value $options[$key] = "Height: $height, Serial No: $serial_no"; } } } return $options; }December 12, 2023 at 12:11 AM in reply to: Feature Request: allow duplicating cloneable fields/groups #44059leebazCDS
ParticipantI'd like to UPVOTE this, it would be great if the clone feature had a 'clone content' option.
leebazCDS
ParticipantI think I found the error, and it links to another issue that I found elsewhere to do with the maximum number of fields groups: when you exceed it the settings get lost, e.g Post_type reverts to 'post' from whatever else it was set to... and similarly the custom setting geo.api_key get's lost too!
October 6, 2023 at 3:56 PM in reply to: Linking Two Custom Post Types in select/dropdown field #43442leebazCDS
ParticipantThis is my attempt to create a select field from custom post type, custom field, but it's not appearing in the builder yet...
Same file structure as my previous post:
<?php add_filter( 'rwmb_field_types', 'register_custom_field_type' ); function register_custom_field_type( $types ) { $types['select_from_sw_customers'] = 'SW_Customers_Select_Field'; return $types; } class SW_Customers_Select_Field extends RWMB_Field { public static function html( $meta, $field ) { // Args for the WP_Query $args = array( 'post_type' => 'sw_customers', 'posts_per_page' => -1, 'post_status' => 'publish' ); $query = new WP_Query( $args ); $options = ""; if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); // Get the custom field value from sw_customers $groups = get_post_meta( get_the_ID(), 'contact_details', true ); foreach ( $groups as $group ) { $customer_name = $group[ 'name' ] ?? ''; } if ( ! empty( $customer_name ) ) { $selected = selected( $meta, get_the_ID(), false ); $options .= "<option value='" . esc_attr( get_the_ID() ) . "' {$selected}>" . esc_html( $customer_name ) . "</option>"; } } wp_reset_postdata(); } return sprintf( '<select name="%s" id="%s">%s</select>', $field['field_name'], $field['id'], $options ); } }October 5, 2023 at 11:42 PM in reply to: Linking Two Custom Post Types in select/dropdown field #43437leebazCDS
ParticipantThanks! I'm trying to register my own field type class to see if I can get this to work.
I have a file called customer-field-type.php in my /inc/ folder.I have put the following into functions.php:
add_action( 'init', 'prefix_load_phone_type' ); function prefix_load_phone_type() { $meta_boxes_extend= get_template_directory() . '/inc/customer-field-type.php'; if ( is_readable( $meta_boxes_extend ) ) { require $meta_boxes_extend; } }In my customer-field-type.php file is the code taken from your example page:
class RWMB_Phone_Field extends RWMB_Field { public static function html( $meta, $field ) { return sprintf( '<input type="text" name="%s" id="%s" class="rwmb-phone" value="%s" pattern="\d{3}-\d{3}-\d{4}">', $field['field_name'], $field['id'], $meta ); } }however, when I go to make a new field in the builder I can't find this new field in the list.
What am I doing wrong? -
AuthorPosts