Skip to:
Content
Pages
Categories
Search
Top
Bottom

If a number have same number get_avatar


  • tipsy
    Participant

    @tipsy

    This is working code that gets the data from a field that registered users have to fill out in their profiles in wordpress:

    <?php 
        $field = xprofile_get_field_data(2, $user_id); 
        echo '<span class="wisfb_carNumber">' . $field . '<span>'; 
    ?>
    

    This is the code that generates data from a Excel-file:

    <?php $data = wp_excel_cms_get("EXCEL-DOCUMENT"); ?>
    
    <?php foreach($data as $entry): ?> 
    
        <?php echo $entry[1]; ?>
    
    <?php endforeach; ?>
    

    Now I want to do this:

    If the number witch is generated in:
    <?php echo $entry[1]; ?>
    is the same number as in the users “Profile fields” witch is 2:

    $field = xprofile_get_field_data(2, $user_id);
    

    get this users avatar:

    echo get_avatar();
    

    Does anyone have an idea on how to do this?

    This is the code I’m trying now. This one spits out the default img but aint getting the users avatar:

    <?php  
    if ($entry[1] === xprofile_get_field_data(2, $user_id));  {
         echo get_avatar($field);
    } 
    ?>
Viewing 10 replies - 1 through 10 (of 10 total)

  • Henry Wright
    Moderator

    @henrywright

    The comparison operator you’re using === checks if $entry[1] and xprofile_get_field_data(2, $user_id) are equal AND are of the same type. Even if they are ‘equal’, if one is type string and one is type int then your comparison will be false. If type isn’t important to you, then just use ==.

    Just something I’d mention for you to keep in mind.


    tipsy
    Participant

    @tipsy

    @henrywright So I’m trying to get this right, this starting to get more and more fun, even if it doesnt work 🙂

    I say if ($entry[1] is the same as == Profile fields 2 (that the user have been forced to write in that field xprofile_get_field_data(2) ); render avatar from the $user_id that match echo get_avatar($field);

    Is this right thinking? But who do I get the $user_id in?

    This is my none working code for now. (This one is still spits out the default-avatar but doesn’t grab the users avatar)

    
    <?php  
    if ($entry[1] == xprofile_get_field_data(2));  {
         echo get_avatar($field);
    } 
    ?>
    

    danbp
    Moderator

    @danbp


    tipsy
    Participant

    @tipsy

    thank you @danbp I will start right away!

    Here is were I am now (not working):

    
    <?php
    if ($entry[1] == xprofile_get_field_data(2, $user_id));  {
         echo bp_core_fetch_avatar($user_id);
    }  
    ?>
    

    tipsy
    Participant

    @tipsy

    @danbp just realized. The $user_id isn’t getting rendered at the page somewhere on the pages. It is just in the database, can this be a part of the problem?


    danbp
    Moderator

    @danbp

    Where should the code work exactly ? On profile or an extra page ?

    So far i understand, you want to show the avatar of a document author generated with WP Excel CMS plugin, i’m right ?

    And you’re using shortcode to generate such a document.

    Fear you have to give much more details…


    tipsy
    Participant

    @tipsy

    @danbp Sorry If I’m blurry, been sitting on and of with this since yesterday 🙂

    1. I have 90 users/subscribers.

    2. All users are forced to write a number when they registerer. This I force them to do with BuddyPress Profile Fields. This field have the id 2, xprofile_get_field_data(2)

    2. I have a plugin “WP Excel CMS” were I render out a excel-document with information on a page. Here I also have numbers. And the value of this cells are $entry[1]

    3. Now when I have xprofile_get_field_data(2) and $entry[1] I want to echo get_avatar() of the $user_id in the database who have this number match.


    danbp
    Moderator

    @danbp

    I don’t know that plugin, sorry.

    xprofile_get_field_data(2) where 2 = field id, this is not the entered value. For what do you need each member to give a number ?

    The field has an ID and a value. What you need is the value, not the ID as all user use the same field ID to enter a number.

    This means if field ID 2 contains 35 or other value, do something and if empty do nothing or else.

    xprofile_get_field_data fetch a value, let’s say 35 (as example)

    Your document has a var $entry[35] with 35 in array.

    User Igor registered on the site with a user ID of 2156. Completed his profile and entered number 35. Igor’s avatar is generated by Gravatar.

    What i don’t understand for the moment is the relation between the document and Igor !

    The usage example given by the author let me doubt that you can bind a user in a excel tab with a BP user avatar, at least because the doc is not stored in the DB, but only screen readable.


    tipsy
    Participant

    @tipsy

    @danbp

    xprofile_get_field_data(2) where 2 = field id, this is not the entered value. For what do you need each member to give a number ?

    I need every player to enter their play-number.

    The field has an ID and a value. What you need is the value, not the ID as all user use the same field ID to enter a number.

    This means if field ID 2 contains 35 or other value, do something and if empty do nothing or else.

    xprofile_get_field_data fetch a value, let’s say 35 (as example)

    Your document has a var $entry[35] with 35 in array.

    User Igor registered on the site with a user ID of 2156. Completed his profile and entered number 35. Igor’s avatar is generated by Gravatar.

    Have to read this ten more times, I’m to new to this, I’ll be back 🙂

    What i don’t understand for the moment is the relation between the document and Igor !

    In the excel file I get points from other players, with results. This is were I need to connect number with number.

    The usage example given by the author let me doubt that you can bind a user in a excel tab with a BP user avatar, at least because the doc is not stored in the DB, but only screen readable.

    Have to google on this subject.


    tipsy
    Participant

    @tipsy

    Here is were I am at the moment:

    
    <?php 
    	$field = xprofile_get_field_data(2, $user_id); 
    	$data = wp_excel_cms_get("EXCEL");
    	if ($field == $data);  {
    	echo get_avatar( get_current_user_id(2, $user_id) ); 
    	}
    ?>
    
Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘If a number have same number get_avatar’ is closed to new replies.
Skip to toolbar