I am trying to: display a custom user field wpcf-u-status
I visited this URL: hidden link
I expected to see: well if the code was correct, the user status radio button should display here (I just need how to get info + then I can setup php to display radio button.
Instead, I got: Everything worked out except for last column.
Below is my code:
<?php
/*
Template Name: Set User Inactive 01
*/
$current_user = wp_get_current_user();
if ( ( ! ($current_user instanceof WP_User) ) || ( ! current_user_can('administrator') ) )
{
print ("<script language='JavaScript'>");
print (" window.parent.location='<em><u>hidden link</u></em>';");
print ("</script>");
exit();
}
?>
<?php
get_header();
?>
<?php
$sql = "SELECT u.ID, u.display_name, u.user_email
FROM $wpdb->users u
INNER JOIN $wpdb->usermeta m ON m.user_id = u.ID
WHERE m.meta_key = 'wp_capabilities' AND m.meta_value LIKE '%salesperson%'
";
// HOW DO I WRITE CODE TO GET VALUE OF wpcf-u-status - in the usermeta table????
$result = mysql_query($sql);
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}
?>
<div id="main-content" class="main-content">
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<br/><br/>
<div align="center" style="font-family:Arial;font-weight:normal;font-size:30px;">Set Status</div>
<br/>
<div align="center">
<form name="Form1" id="Form1" action="<em><u>hidden link</u></em>" method="post" >
<table width="800" align="center">
<tr height="20">
<td colspan=4 align=right>
<a href="<em><u>hidden link</u></em>"><img src="<em><u>hidden link</u></em>" width="30" /></a>
</td>
</tr>
<tr bgColor="gainsboro" height="40">
<td>
<span style="font-weight:bold;">User ID</span>
</td>
<td align="left">
<span style="font-weight:bold;">Name</span>
</td>
<td align="left">
<span style="font-weight:bold;">Email</span>
</td>
<td align="left">
<span style="font-weight:bold;">User Status</span>
</td>
</tr>
<?php
while ($row = mysql_fetch_row($result))
{
echo "<tr>";
$iCount = 1;
foreach ($row as $cell)
{
if ($iCount ==1)
{
echo "<td><input style='border: 0px;' type=text size=2 name=ids[] value=$cell readonly></td>";
$iCount++;
}
else
{
echo "<td>$iCount : $cell</td>";
$iCount++;
}
}
echo "</tr>\n";
}
mysql_free_result($result);
?>
<tr height="150">
<td colspan=4 align="center"><input style="padding: 12px;"; type=submit value=' Update Records '></td>
</tr>
</table>
</form>
<br/><br/>
<br/><br/>
</div>
<br/><br/>
<br/><br/>
<br/><br/>
<br/><br/>
<br/><br/>
<br/><br/>
<?php
get_footer();
?>
Dear Kathy,
I suggest you query the users with wordpress built-in class WP_User_Query,
https://codex.wordpress.org/Class_Reference/WP_User_Query
for example:
$args = array(
'meta_query' => array(
array(
'key' => 'wp_capabilities',
'value' => 'salesperson',
'compare' => 'LIKE'
),
),
'fields' => array(
'ID', 'display_name', 'user_email'
),
);
$user_query = new WP_User_Query( $args );
$user_query = $user_query ->get_results();
As you can see above codes will be able to get the user's ID, then use wordpress function get_user_meta() to display the user field "wpcf-u-status"
https://codex.wordpress.org/Function_Reference/get_user_meta