WordPress.org

Forums

Buddypress Xprofile Custom Fields Type
[resolved] PHP If Statement Help (3 posts)

  1. jslom
    Member
    Posted 1 year ago #

    Hello, and thank you for such a wonderful plugin!

    I have successfully used some if statements to pull information and display an image depending on the users selection, but need help with the last one.

    First, this is one of the examples of a field I am pulling..

    <?php
    $platform = xprofile_get_field_data( 'What platform do you play on the most?', $member_id ); if ( $platform == 'Playstation 3' ) echo '<img src="ps3-icon.png">'
    ?>

    Where "What platform do you play on the most?" is the name of my selection box. The one above works fine for a drop down selection box.

    I am trying to do the same if statement, but with a checkbox setup and it doesn't seem to use the same code.

    I've tried a few variations of code like below, but have been unsuccessful on getting it to display.

    <?php
    xprofile_get_field_data( 'What Games Are You Frequently Playing?', $member_id ); if ( $games == (isset($_POST['Call Of Duty: Ghosts'])) && $_POST["Call Of Duty: Ghosts"] == 1 ) echo '<img src="codghosts.png">'
    ?>

    Any help would be wonderful, thanks! Also if you notice anything I am doing wrong, please let me know I am still learning!

    http://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/

  2. donmik
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    This is not in the scope of my plugin...

    Checkboxes are stored as an array. If you make a var_dump of the data like this:

    <?php $games = xprofile_get_field_data( 'What Games Are You Frequently Playing?', $member_id ); var_dump($games); ?>

    You will see something like this:

    array (size=2)
      0 => string 'Call of Duty' (length=12)
      1 => string 'Other games' (length=11)

    So, to check against an array you must do this:

    if (in_array('Call Of Duty: Ghosts', $games)) echo '<img src="codghosts.png">';

  3. jslom
    Member
    Posted 1 year ago #

    Thank you!

    I had the code last night that worked, and now I seemed to have not saved it lol

    I will try and figure it out again with the code above!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Buddypress Xprofile Custom Fields Type
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.