[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

wp get_user_meta - get an array or row?

Posted on 2014-08-19
2
Medium Priority
?
480 Views
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...

Thanks,

Chris
0
Comment
Question by:St_Aug_Beach_Bum
2 Comments
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 2000 total points
ID: 40273784
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.
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 40274361
Got it, thank you very much!

Chris
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 9 hours left to enroll

868 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