0

I'm using the plugin "Extra User Fields" to add extra fields to the user's profile. I know how to get the value of the field (get_user_meta/get_author_meta), but I also want the label as a string, but I don't want to get the full code (like <label>Label</label><input value="value" /> etc., because I want to be able to do with the label and the value what I please.

So, what function (or tag) should I use to get the label value of an user field?

5
  • You can already get the label but you ALSO get the input with it right? Commented Apr 17, 2012 at 18:41
  • Yes, I just want the "values" as strings, not wrapped in html labels and inputs... Commented Apr 17, 2012 at 18:44
  • Could you post an example of what you've tried that isn't giving you the desired results? Commented Apr 17, 2012 at 18:53
  • Yes. do_action( 'edit_user_profile', $profileuser ); gives me all the user profile fields (labels, input and help wrapped in html elements, ready for output to the browser), but I just want the label value on it's own. I can get the input value with get_the_author_meta('field_id'), but I have no idea how to get just the label value that goes with that input value.. Commented Apr 17, 2012 at 18:59
  • The plugin appears to be intended for people to use in the administration area, are you extending the plugin or are you editing the plugin? The plugin doesn't look like it supports PHP execution from the admin area - so I am just trying to get some context. Commented Apr 17, 2012 at 19:57

1 Answer 1

0

Mentioned Functions:

If you can already get the label BUT it comes with the input, and you are doing this in PHP, then do this:

<?php
    # ...
    # Your code which produces the input + label data into $data
    # ...
    $document = new DOMDocument();
    $document->loadHTML( $data );
    $xpath = new DOMXPath( $document );
    $entries = $xpath->evaluate("//label");
    $results = array();
    foreach( $entries as $entry ) {
        $results[] = '<' . $entry->tagName . '>' . $entry->nodeValue .  '</' . $entry->tagName . '>';
    }
    print_r($results);
?>

This question appears incomplete from my outside perspective, so if this doesn't solve your problem, please refer to the discussion under the original question (in the comments section) so I may formulate a more appropriate response.

2
  • Oke, so what this does is load the data (label, input and someimes more) wrapped in the html-elements, and then parses that to get the desired strings? I've thought of that, but I was hoping there would be a cleaner/direct way to get the label. Anyway, thanks! I will try it like this! Commented Apr 17, 2012 at 21:26
  • If this answer was acceptable please mark it as "Accepted". I'll see if I can look into a more efficient method - but for now this will do. Commented Apr 18, 2012 at 6:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.