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
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();
-
And it's recommended do in that way in a common
front-page.php
file? Commented Feb 6, 2015 at 22:58 -
It is recomended to wrap this code in a function and move it in
functions.php
. Infront-page.php
call the function to get your users ids.– AlexeyCommented 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 Commented Feb 6, 2015 at 23:34
-