skip to Main Content

I have a question about php (wordpress) I have a plugin(buddypress) with function bp_the_profile_field_name();

when i use

echo bp_the_profile_field_name();

It’s return "Tags"

But..

if (bp_the_profile_field_name() == "Tags"){
    echo "Yes, it's working";
} else {
    echo "Oh no..";
        }
?>

its return "Oh no.."
When i try equal to string "Tags" dosent’t match.
Why? Please help

2

Answers


  1. When googling to the source of the bp_the_profile_field_name function I found this source:

    function bp_the_profile_field_name() {
        echo bp_get_the_profile_field_name();
    }
    

    Here we can see that the the function uses echo to show the value.


    If you want to get the value to compare it with something else you’ll need to use a other function which will return the value.

    Below the mentioned page in the ‘related’ part this function is mentioned:

    bp_get_the_profile_field_name

    Returns the XProfile field name.

    Note the _get_ insteaf off _the_

    Which returns a string. Source can be found here.

    So your code should become:

    if (bp_get_the_profile_field_name() == "Tags"){
        echo "Yes, it's working";
    } else {
        echo "Oh no..";
    }
    
    Login or Signup to reply.
  2. According to documentation (https://www.buddyboss.com/resources/reference/functions/bp_the_profile_field_name/) bp_the_profile_field_name() echoes output.

    If you want to compare the output of this function you need a return, not echo.

    You have 2 options:

    1. Use bp_get_the_profile_field_name() instead of bp_the_profile_field_name() in your if statement
    2. Edit bp_the_profile_field_name() to output the result instead of echoing it.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search