0

I have a meta field in user called columnista-destacado I need to iterate through Wordpress users and if that field has valued set (lets said equal 1) then I need to display user meta info at front-page. Should be 6 users at maximum, how I can do that?

1 Answer 1

2

Sometimes it is more useful to look at the task outside of the WordPress field, but from true programming. You can use custom SQL query to get your users ids and then do what you want with them.

Place the code below into functions.php

function wpse_177536_get_user_ids(){
    global $wpdb;
    $sql = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key='columnista-destacado' AND  meta_value = '1' LIMIT 6";
    $user_ids = $wpdb->get_col($sql);
    return $user_ids;
}

Now anywhere, for example, in front-page.php you can call this function like this:

$user_ids = wpse_177536_get_user_ids();
4
  • And it's recommended do in that way in a common front-page.php file?
    – ReynierPM
    Commented Feb 6, 2015 at 22:58
  • It is recomended to wrap this code in a function and move it in functions.php. In front-page.php call the function to get your users ids.
    – Alexey
    Commented Feb 6, 2015 at 23:12
  • Can you edit your post and show me how to do that? I'm not so expert at WP this are my first steps
    – ReynierPM
    Commented Feb 6, 2015 at 23:34
  • I've updated the post, as you asked.
    – Alexey
    Commented Feb 7, 2015 at 6:13

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.