Skip Navigation

[Resolved] error trying to get a new field called wpcf-u-status in the usermeta table

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 8 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 1 reply, has 2 voices.

Last updated by Luo Yang 8 years ago.

Assisted by: Luo Yang.

Author
Posts
#453217

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();
?>


#453306

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

The forum ‘Types Community Support’ is closed to new topics and replies.