• Resolved peteratomic

    (@peteratomic)


    I’m using a custom profile template in order to control design and content structure. In my template, various fields like this work fine:

    <?php echo um_user('nickname'); ?>

    However, when I tried using this with the metakey I created, the output is “Array”. So…

    <?php echo um_user('mybands'); ?>

    Just outputs “Array”.

    Possible you could provide the code for displaying the content so I can use it in a custom template?

    Thanks in advance!

    https://wordpress.org/plugins/um-relational-fields/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author PlusPlugins

    (@plusplugins)

    Assuming that mybands is one of the fields set up with this plugin and thus only contains ids, but you want the actual name of the band to display you can do something like this:

    <?php if (um_user('student_subjects')) {
    $subjects = um_user('student_subjects');
    $subject_output = array();
    foreach ($subjects as $subject) {
      $subject_output[] = get_the_title( $subject );
    }
    echo implode(", ",$subject_output);
    } else { echo "No data";} ?>

    The above code was however used for a link to a custom post type. If mybands is linking to another user role the code would have to be adjusted for getting user data.

    See https://codex.wordpress.org/Function_Reference/get_userdata

    Thread Starter peteratomic

    (@peteratomic)

    Ah yes, its for a user role. Sorry I didn’t say that before.

    Plugin Author PlusPlugins

    (@plusplugins)

    You can try the following code, but it is untested.

    <?php if (um_user('mybands')) {
    $bands = um_user('mybands');
    $bands_output = array();
    foreach ($bands as $band) {
      $user_info = get_userdata($band);
      $bands_output[] = '<a href="' . get_permalink(get_option('um_core_pages')['user']) . $user_info->ID . '">' . $user_info->display_name . '</a>';
    }
    echo implode(", ",$bands_output);
    } ?>
    Thread Starter peteratomic

    (@peteratomic)

    Oh my god, it works!! THANK YOU!

    Five stars review!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘code for custom profile templates’ is closed to new replies.