• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Searching for customFields

#1
Hey there,

I am trying to search for all users that have a specific value in a specific custom field.
I guess my non-working code shows best what I am trying to do:

PHP:
$userModel = new XenForo_Model_User();
$criteria = array(
       'customFields' => array("my_custom_field" => "bunny"),
);

$options = array(
       'join' => XenForo_Model_User::FETCH_USER_PROFILE,
);

$users = $userModel->getUsers($criteria, $options);
Also, how does the customFieldsExact work?
 

Daniel Hood

Well-known member
#2
This actually looks like it should be working, what's it doing? Have you looked at the debug output for the query?

customFieldsExact requires an exact match. For example with our code it'd also match "abuNNy3" whereas if you use customFieldsExact it has to literally be "bunny".
 
#3
I am getting all users in return, as if I hadnt specified any criteria.
How can I enable debug query, I am developing this piece of code in a custom file with the following header:
PHP:
$fileDir = realpath(dirname(__FILE__) . '/../../');
chdir($fileDir);
require_once($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');
XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Error::setIgnorePendingUpgrade(true);
XenForo_Phrase::setPhrases(require($fileDir . '/install/language_en.php'));
XenForo_Template_Install::setFilePath($fileDir . '/install/templates');
XenForo_Application::get('db')->setProfiler(true);
XenForo_Application::setDebugMode(true);