I am trying to: write a query where I have added a new custom field to the wp_users table called u-status
I visited this URL:
I expected to see: something
Instead, I got: no results
<?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
A.ID, A.user_login, A.user_nicename,
A.user_email, B.meta_value
FROM wp_users A
INNER JOIN wp_usermeta B ON A.ID = B.user_id
WHERE B.meta_key = 'wpcf-u-status'";
global $wpdb;
$result = $wpdb->get_results ( $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 Salespeople Inactive</div>
<br/>
<div align="center">
<form name="Form1" id="Form1" action="<em><u>hidden link</u></em>" method="post" >
<table width="700" 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;">Username</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>
</tr>
SOMETH8ING GOES HERE
</table>
<br/><br/>
<br/><br/>
</div>
<br/><br/>
<br/><br/>
<?php
get_footer();
?>
Hi
I have updated my code as follows, but it still isn't working
I need to display in a table format only those users who
have the role of Salesperson.
I have tried everything and I can't seem to get this query
working at all.
<?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
// $blogusers = get_users( 'blog_id=1&orderby=nicename&role=Salesperson' );
$sql = "SELECT
A.ID AS 'User ID',
A.display_name AS Name,
A.user_email AS Email,
B.meta_value AS Status,
C.meta_value AS Role,
FROM wp_users A
INNER JOIN wp_usermeta B ON A.ID = B.user_id
INNER JOIN wp_usermeta C ON A.ID = C.user_id
WHERE B.meta_key = 'wpcf-u-status'
AND C.meta_key = 'salespeople' ";
$result = mysql_query($sql);
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}
else
{
print ("there are results\n\n\n\n");
}
$result = mysql_query($sql);
if (!$result) {
die("Query to show fields from table failed");
}
$num_rows = mysql_num_rows($result);
echo "$num_rows Rows\n";
$fields_num = mysql_num_fields($result);
echo "<h1>Table: {$table}</h1>";
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>
Hi
Sorry for all the emails... I'm stuck for sure now
Here is my code... I don't know how to reference the newly created
field wpcf-u-status and how I would go about updating it as well
$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%'
// need to check for value of this field: wpcf-u-status - in the usermeta table
ORDER BY u.user_registered";
$result = mysql_query($sql);
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}
not really, but I am going to re-post