Skip Navigation

[Closed] when I modified query now can't access custom fields

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 7 years, 4 months 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 3 replies, has 2 voices.

Last updated by Luo Yang 7 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#469636

HI

I have a number of custom fields I have created for the Users entity.

I have a sreen where the user can check off which client records to issue a cert. for (see screenshot).

On my php page, I am able to determine the RecID for each of the checked clients ok.

Then I have a loop which updates a date (if rec was selected) and then I need to grab the custom fields
that are on the Users entity for the appropriate ID and on a separate table for the Client of the User.

Below is my loop. However, something is wrong because I can't access the Types custom fields.

foreach ( $iSelectedRecs as $iRec_ID )
{
$sql = "UPDATE wp_transure_cust_clients ";
$sql .= "SET Acord_Date = \"$sNew_Acord_Date\" ";
$sql .= "WHERE Rec_ID = $iRec_ID";

$result = mysql_query($sql);

if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}

$sql = "SELECT DISTINCT ID, display_name, user_email FROM wp_users ";
$sql .= "INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id ";
$sql .= "INNER JOIN wp_transure_cust_clients ON wp_transure_cust_clients.User_ID = wp_users.ID ";
$sql .= "WHERE wp_users.ID = $iCustID ";
$sql .= "AND wp_transure_cust_clients.Rec_ID = $iRec_ID ";

$result = mysql_query($sql);

if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}

/* HERE ARE JUST A FEW OF THE CUSTOM FIELDS */

$user_id = $iCustID;
$single = true;

$key1 = "wpcf-status";
$sStatus = get_user_meta($user_id, $key1, $single );

$key2 = "wpcf-hdr-customer-name-address";
$sCustInfo = get_user_meta($user_id, $key2, $single );

.... other code goes here....

}

I visited this URL:

I expected to see:

Instead, I got:

#469751

Dear kathy,

It is a custom PHP codes problem, according to our support policy, we do not provide the custom codes support:
https://toolset.com/toolset-support-policy/

I suggest you try to debug your PHP codes manually, line by line
For example:

...
$result = mysql_query($sql);
print_r($result); // here check if the $result is correct
...
#469967
screenshot-02.jpg
screemshot-01.jpg

Hi

I have updated my sql code and when I run the sql code without referencing any custom fields it works (see attached screenshots). I displayed the record id and the rowcount for each.

here is my code...

foreach ( $iSelectedRecs as $iRec_ID )
{
$sql = "SELECT DISTINCT ID, display_name, user_email ";
$sql .= "FROM wp_users ";
$sql .= "INNER JOIN wp_usermeta ON wp_users.ID = wp_usermeta.user_id ";
$sql .= "INNER JOIN wp_transure_cust_clients ON wp_users.ID = wp_transure_cust_clients.User_ID ";
$sql .= "WHERE wp_users.ID = $iCustID ";
$sql .= "AND wp_transure_cust_clients.Rec_ID = $iRec_ID ";

$result = mysql_query($sql);
$rowcount = mysql_num_rows($result);

print ("<br>Rec ID: $iRec_ID");
print ("<br>Rowcount: $rowcount");

if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}

$user_id = $iCustID;
$single = true;

$key1 = "wpcf-status";
$sStatus = get_user_meta($user_id, $key1, $single );

$key2 = "wpcf-hdr-customer-name-address";
$sCustInfo = get_user_meta($user_id, $key2, $single );

print ("<br>Status: $sStatus");
print ("<br>CustInfo: $sCustInfo");
}

I have this custom code section that I used elsewhere that works there but not here

I don't think this is a sql error issue

#470089

It is a custom PHP codes problem, if you need more assistance, please duplicate same problem in a test site, and fill below private detail box with login details and FTP access, also point out the problem page URL and where I can edit your PHP codes.

The topic ‘[Closed] when I modified query now can't access custom fields’ is closed to new replies.