Forum Replies Created
-
AuthorPosts
-
January 24, 2024 at 5:11 AM in reply to: Remote validation for uniquenes - how to prevent when editing existing post? #44376
phillcoxon
ParticipantHi Peter,
Thank you for the response.
For:
(2) are you able to offer any example of how I can prevent saving and return the user to the editor with an error message if using
rwmb_before_save_post?(3) Let me clarify this. Would you confirm that if I am using the Metabox Builder and I try to return a custom validation error message via code from the validation function (above), that it will be ignored? Using the Metabox Builder prevents the validation error from being returned via code and only pays attention to the validation message in the Metabox Builder, even if that field is left blank?
Thanks in advance!
January 21, 2024 at 1:23 AM in reply to: โ How can I pre-populate fields in new frontend submission? #44358phillcoxon
ParticipantThank you.
Here's how I ended up doing this with code in functions.php:
// Check if the current page is the "add new post" front end submission page for the "tramp-log" custom post type $current_page_id = get_the_ID(); //if (is_page('15585')) { if ($current_page_id == "15585") { /* see https://docs.metabox.io/filters/rwmb-field-meta/ */ add_filter("rwmb_tramp_id_field_meta",function ($value, $field, $saved) { $value = isset($_GET["tramp_id"]) ? $_GET["tramp_id"] : $value; return [$value, $field]; },10,3); }November 11, 2023 at 2:19 AM in reply to: How to validate just the value in a key_value pair? #43788phillcoxon
ParticipantHi Peter,
Are you able to confirm if remote validation will work for key_value fields if multiple key_value pairs have been added?
Will the remote validation get called on each key_value pair in turn as the user enters data into a pair and then clicks away?
Thanks in advance!
November 11, 2023 at 2:09 AM in reply to: How to validate just the value in a key_value pair? #43787phillcoxon
ParticipantHi Peter,
Thank you.
It looks like I should be able to do it with remove validation. I'll give that a go.
July 2, 2023 at 12:01 PM in reply to: โ How to dynamically populate a new post custom field from url? #42442phillcoxon
ParticipantThanks so much!
phillcoxon
ParticipantSolved it!
Found rwmb_get_field_settings(). ๐
This is my shortcode now which is working great.
Thanks again!
/** * @return false|string * * Shortcode to display compositon */ function sock_composition_func() { ob_start(); // grab the details of subfields in the composition_group MetaBox group. $sockcomp = rwmb_meta('composition_group'); if ( empty( $sockcomp ) ) { return 'No sock composition values have been entered.'; } // get the subfields of the composition_group MetaBox group $subfields = rwmb_get_field_settings('composition_group')[fields]; $composition = array(); // Loop through and add "Name: Value%" to an array. foreach ($subfields as $subfield ) { $composition[] = $subfield['name']. " ". rwmb_meta($subfield['id']) . "%"; } // return as comma separated output, excluding last comma echo '<span class="composition-list">' . implode(", ", $composition) . '</span>'; return ob_get_clean(); } add_shortcode('sock_composition', 'sock_composition_func');phillcoxon
ParticipantHi Long,
Thanks for the fast reply.
Ah... I see where I was confused now.
I assumed when I created a new Custom Fields "Field Group" using WP-Admin -> MetaBox -> Custom Fields that this was a MetaBox group that the sample code would work with. Newbie mistake.
I now see the Group option in the WP-Admin -> MetaBox -> Custom Fields UI, have moved the indivdiual fields in and I'm now getting each $key => $value back using a foreach loop.
Thank you!
So the final question I have is... how can I retrieve the field Name and Description as well as the field value?
Using the fields above (now in a group) I want to output a list of sock composition elements. For example; "Cotton 72%, Elastic 10%, Combed Cotton 18%".
It would be great if I could retrieve the field Name, Description, as well as the id and value - are you able to tell me how to do this?
I'm sure it's simple, but I'm still noobing through the documentation and haven't spotted it.
Absolutely loving MetaBox though - this is amazing.
-
AuthorPosts