• Resolved tcmacadmind

    (@tcmacadmind)


    Hi, I have a Club Membership website and use UM to register all of our members. I have created a Profile form that works well and I have recently added a field for Date First Joined, but would like to also create a field to automatically show the number of years and months that a member has been a member calculated from the Date First Joined field. Can this be done and if so how?

    I am not very experienced in WordPress or the programming of this sort of thing so a plain English explanation or link to a guide/plugin would be great.

    Thanks for any assistance that may be forthcoming.

    cheers Dave

Viewing 12 replies - 16 through 27 (of 27 total)
  • Thread Starter tcmacadmind

    (@tcmacadmind)

    Hi missveronica, I did add my title name to the snippet but because the form field is a shortcode field it does not give me a Label name or a meta Key name to use and the title name advises that it is for the backend only and won’t appear on the front end so Im guessing that it won’t work for me. Anyway, thank you again for all of your assistance with this project I very much appreciate your help.

    Regards Dave

    @tcmacadmind

    Can you show me your shortcode here in the forum?

    Thread Starter tcmacadmind

    (@tcmacadmind)

    Hi missveronica, sure, my short code field is
    [my_human_time_diff meta_key=”membership_year_28″]
    with the membership_year_28 being the meta key for the field that the date is in, is that what you want? The other fields for the short code are just Title, Privacy,Select Member Roles and Visibility.

    If you have a private way of emailing I can send a screen capture of the form field or even give you admin access so you can see it yourself if you think that would be helpful.

    @tcmacadmind

    The label text you implement like this in your shortcode:

    [my_human_time_diff meta_key=”membership_year_28″ label="Membership since"]

    or any other text for the label.
    This works with your current code snippet installed.

    Thread Starter tcmacadmind

    (@tcmacadmind)

    Hi missveronica, I don’t know what happened but the field disappeared completely from the form, I tried to fix it but ended up losing other fields as well so I am currently installing a backup of the whole database to get back to where it was yesterday.

    Thread Starter tcmacadmind

    (@tcmacadmind)

    Hi missveronica. I have started from scratch after loading a backup of the website from before I started this process. I re did everything that you have advised and it all works perfectly until I add the last update for the shortcode which added the label parameter. When I use this it no longer displays either the field or a label. The shortcode that is causing problems is

    [my_human_time_diff meta_key=”date_joined″ label=”Membership since”]

    The shortcode that works expect for showing a label is

    [my_human_time_diff meta_key=”date_joined”]

    the snippet I am using is

    /*
    *       [my_human_time_diff meta_key=" date_joined " label="MyLabelText"]
    */
    
    add_shortcode( 'my_human_time_diff', 'my_human_time_diff' );
    
        function my_human_time_diff( $atts ) {
    
            if( is_array( $atts ) && isset( $atts['meta_key'] )) { 
                um_fetch_user( um_profile_id());
    
                if( is_numeric( um_user( $atts['meta_key'] ) )) {                
                    $first_time = um_user( $atts['meta_key'] );
                } else {
                    if( is_string( um_user( $atts['meta_key'] ) )) $first_time = strtotime( um_user( $atts['meta_key'] ));
                    else $first_time = false;
                }
                if( $first_time ) {
                    if( isset( $atts['label'] )) $label = $atts['label'] . ' ';
                    else $label = ''; 
                    return '<div>' . $label . human_time_diff( $first_time, strtotime( wp_date( 'Y-m-d H:i:s' ))) . '</div>';
                } else return '';
            } else return '<div>Shortcode parameter error</div>';
        }

    Can you offer any advice please?
    regards
    Dave

    @tcmacadmind

    Replaced my reply with new text:

    I found that copying the text from the Forum to the shortcode
    will give you wrong versions of the symbol: ”

    Use your keyboard and replace all the ” in your shortcode in the form
    with the keyboard version of the “

    Old reply text ( if above solution didn’t fix the issue ):

    Why did you change from “membership_year_28″ to ”date_joined″?

    Can you show me here in the forum examples of the content in those two fields?

    • This reply was modified 2 years, 4 months ago by missveronica.
    • This reply was modified 2 years, 4 months ago by missveronica.
    • This reply was modified 2 years, 4 months ago by missveronica.
    • This reply was modified 2 years, 4 months ago by missveronica.
    • This reply was modified 2 years, 4 months ago by missveronica.
    Thread Starter tcmacadmind

    (@tcmacadmind)

    Hi missveronica, I replaced the quote marks in the shortcode and it worked. All is great now. Thank-you so much for your patience with me and again I am very thankful for all of you assistance with this.
    regards
    Dave

    @tcmacadmind

    Thanks Dave.

    For all UM users including all users with non-english sites I have made an updated code snippet where local languages can be used.

    The label text and the time difference text have both been included in a format parameter for translation possibilities.

    https://github.com/MissVeronica/um-form-shortcode-1

    You don’t need to update your site as long as your current text is OK.
    If you want to replace the last word “ago” with something else this updated code snippet can be your solution.

    Thread Starter tcmacadmind

    (@tcmacadmind)

    Thanks again missveronica

    Thread Starter tcmacadmind

    (@tcmacadmind)

    Hi again missveronica, I am just having a small issue with what we did with the calculated field in that when I export my data to an excel or csv file, the option to select the calculated field that we created is not there. When I queried this with the plugin developer for the export plugin (WP Smart Export) he replied with the following message;

    Does ‘UM profile’ store fields as post or user meta fields? If the fields are stored on a custom table, they will not show up.

    WP Smart Export can only list fields that are stored as native WP user or post meta fields.

    Are you able to shed any light on this please, I am not sure how the data is stored.

    Thanks again
    Dave

    @tcmacadmind

    No, you can’t get the calculated field in the download but you can download the source (the value of the meta key in the shortcode) for calculating the time difference again in Excel.

    https://support.microsoft.com/en-us/office/calculate-the-difference-between-two-times-e1c78778-749b-49a3-b13e-737715505ff6

Viewing 12 replies - 16 through 27 (of 27 total)
  • The topic ‘Calculated field for profile Form’ is closed to new replies.