wp get_user_meta - get an array or row?

Posted on 2014-08-19
Last Modified: 2014-08-20
I'm trying to make my wordpress script as efficient as possible.

Right now, I'm doing this:

$author_id is set.


$author=get_the_author_meta( 'user_login',$author_id);

$author_name=get_the_author_meta( 'first_name',$author_id);

$authLevel = get_the_author_meta( 'user_level',$author_id);


Is there a way to use an array in that so I can do it with one call to mysql?

Or.. would it be more efficient to call the whole row (get_user_meta($author_id)) rather than ask for three particular things, and then pull them out of that?

Or is the way I am already doing it the most efficient?

Likewise, is there a way to change this so it's one mysql access?


$overall = $wpdb->get_var("SELECT overall FROM adshare WHERE author = '$author'"); //get number
$wpdb->query("UPDATE adshare SET overall = overall+1 WHERE author = '$author'"); //add one to number in db


I would need $overall to give me the pre-update number though...


Question by:St_Aug_Beach_Bum
    LVL 14

    Accepted Solution

    If the get_user_meta() function returns all the info you need, it would be more efficient as one database call uses less resources than three separate calls.  The only time that may not be true is if your single query had a lot of table joins in the query as joins are fairly expensive operations.

    I assume that you need the value of $overall somewhere else in your code and that is why you are making the two queries.  The second query is independent of the first one.  If you don't need the pre-value of $overall then you don't need to make the first query.  If you want the value of $overall then you need to do the two queries.

    Author Comment

    Got it, thank you very much!


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    WordPress is constantly evolving, and with each evolution appears to get better and better.  One of the big drawbacks prior to version 3 was that there was no way to be able to set up a custom menu from the backend. The Old Way Adding menus is…
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now