Support Forum ยป User Profile

Forum Replies Created

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • phillcoxonphillcoxon
    Participant

    Hi 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!

    phillcoxonphillcoxon
    Participant

    Thank 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);
    }
    
    in reply to: How to validate just the value in a key_value pair? #43788
    phillcoxonphillcoxon
    Participant

    Hi 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!

    in reply to: How to validate just the value in a key_value pair? #43787
    phillcoxonphillcoxon
    Participant

    Hi Peter,

    Thank you.

    It looks like I should be able to do it with remove validation. I'll give that a go.

    phillcoxonphillcoxon
    Participant

    Thanks so much!

    in reply to: โœ…Shortcode will not show custom field group #19260
    phillcoxonphillcoxon
    Participant

    Solved 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(",&nbsp;&nbsp;", $composition) . '</span>';
    
        return ob_get_clean();
    }
    add_shortcode('sock_composition', 'sock_composition_func');
    in reply to: โœ…Shortcode will not show custom field group #19259
    phillcoxonphillcoxon
    Participant

    Hi 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.

Viewing 7 posts - 1 through 7 (of 7 total)