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

Searching for customFields

Discussion in 'XenForo Development Discussions' started by granis, Jan 20, 2016.

  1. granis

    granis Member

    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:

    $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?
  2. Daniel Hood

    Daniel Hood Well-Known Member

    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. granis

    granis Member

    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:
    $fileDir realpath(dirname(__FILE__) . '/../../');
    $fileDir '/library/XenForo/Autoloader.php');
    XenForo_Autoloader::getInstance()->setupAutoloader($fileDir '/library');
    XenForo_Application::initialize($fileDir '/library'$fileDir);
    XenForo_Phrase::setPhrases(require($fileDir '/install/language_en.php'));
    XenForo_Template_Install::setFilePath($fileDir '/install/templates');

Share This Page