latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

if/else with Custom User Field

Home Forums Community Forum Unofficial Extensions/Hacks if/else with Custom User Field

This topic contains 3 replies, has 2 voices. Last updated by  Eduan 3 years, 7 months ago.

Topic Author Topic
Posted: Saturday May 25th, 2013 at 11:39 pm #50647
Ryan McNeil
Username: rmcneil

I am working on a member site using s2member and have written a bit of code to list user names, emails, and urls on a public directory as result of search terms. However, I would like to allow the user to choose if they would like their name to be listed or not. I thought an if/else statement would be the way to go.

This is what I came up with:

<?php
    $blogusers = get_users('search=Action Theatre');
    $radiobox = get_user_field ("public_directory_yesno");
    foreach ($blogusers as $user) {
     if($radiobox=Yes){
        echo &#039;<tr>';
        echo '<td style="width:3%"></td>';
        echo '<td style="width:15%"><h4>' . $user-&gt;user_firstname . "&amp;nbsp" . $user-&gt;user_lastname . '</h4></td>';
        echo '<td style="width:3%"></td>';
        echo '<td><p>' . $user-&gt;user_email . '</p></td>';
        echo '<td>' . $user-&gt;user_url . '</td>';
        echo '</tr>';}
     else {
        echo '';
        }
    }
?&gt;

The users come up perfectly based on the search term, but it’s not filtering anything based on whether the radio box is checked yes or no. I wasn’t sure what to put as the custom field variable i.e.

$radiobox=Yes

My custom field is a radio box with the values:

Yes | Yes
No | No

It’s probably a syntax thing…what does anyone think?

Thanks!

Ryan

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Wednesday May 29th, 2013 at 1:31 pm #50850
Eduan
Username: Eduan
Moderator

Your conditional is wrong Ryan. :)

It should be:

$radiobox == 'Yes'

Also, your custom field should be:

Yes|Yes
No|No|default

– Eduan

Posted: Wednesday May 29th, 2013 at 6:36 pm #50881
Ryan McNeil
Username: rmcneil

Thanks, Eduan.

The conditional works now. Also, it turns out I needed to call the user field after the foreach function. Here’s what I ended up with and it works perfectly!

<?php
    $blogusers = get_users('search=Action Theatre');
    
    foreach ($blogusers as $user) {
    
    $radiobox = get_user_field ("public_directory_yesno", $user);
     
     if($radiobox == 'Yes'){
        echo '<tr>';
        echo '<td style="width:3%"></td>';
        echo '<td style="width:15%"><h4>' . $user->user_firstname . "&nbsp" . $user->user_lastname . '</h4></td>';
        echo '<td style="width:3%"></td>';
        echo '<td><p>' . $user->user_email . '</p></td>';
        echo '<td>' . $user->user_url . '</td>';
        echo '</tr>';}
     else {
        echo '';
        }
    }
?>

Thanks again for the help!

Posted: Friday May 31st, 2013 at 11:55 am #51060
Eduan
Username: Eduan
Moderator

Excellent! Glad you figured out the problem. :)

Viewing 3 replies - 1 through 3 (of 3 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.