0

I'm a newbie to Wordpress. I'm trying to make custom page that displays contact info for all users. I use code snippet provided by THIS POST.

<ul>
<?php
    $blogusers = get_users('blog_id=1&orderby=nicename');
    foreach ($blogusers as $user) {
        echo '<li>Nick: ' . $user->user_nicename . '</li>';
        echo '<li>Name: ' . $user->display_name. '</li>';
        echo '<li>Email: ' . $user->user_email. '</li>';
    }
?>
</ul>

It works, but it also shows this warning at the top:

Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'yoursite_pre_user_query' not found or invalid function name in C:\xampp\htdocs\mytheme\wordpress\wp-includes\class-wp-hook.php on line 287

What should I do to resolve this?

1
  • The cause of that warning is not in the code block you added
    – Tom J Nowell
    Sep 13, 2020 at 0:02

1 Answer 1

1

Somewhere in your theme or plugins, you must have a line like this add_action( 'something', 'yoursite_pre_user_query' ). Find it and remove or fix it.

Also, the get_users function has since been updated. Your first parameter must be an array.

<ul>
<?php
    $blogusers = get_users( array('blog_id' => 1, 'orderby' => 'nicename') );
    foreach ( $blogusers as $user ) {
        echo '<li>Nick: ' . $user->user_nicename . '</li>';
        echo '<li>Name: ' . $user->display_name. '</li>';
        echo '<li>Email: ' . $user->user_email. '</li>';
    }
?>
</ul>
4
  • After updating parameter it still gives the same warning.
    – Sev.
    Sep 12, 2020 at 15:43
  • Somewhere in your theme or plugins, you must have a line like this add_action( 'something', 'yoursite_pre_user_query' ). Find it and remove or fix it.
    – Greys
    Sep 12, 2020 at 23:42
  • @sav the code block in this answer improves the code in your question but it isn't the answer, it's just Greys being helpful. The first part is the important part. Somewhere in your theme or in a plugin the file mentions yoursite_pre_user_query, remove that line. Think of it like asking how to fix a door, Greys is telling you how to fix the door, and also pointing out there's a broken window and how to fix that too.
    – Tom J Nowell
    Sep 13, 2020 at 0:01
  • Thank you, works as a charm. Indeed, it was a line in plugin. @TomJNowell I can see that "window" problem, but Greys posted (edited) solution later - that caused the commotion
    – Sev.
    Sep 13, 2020 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.