Skip to content
Advertisement

WordPress how to display user_meta array as a table?

I have tried posting this on WordPress stackoverflow, but haven’t got any answers.

This is PHP + WordPress question, so maybe someone here could help.

Ok, so I’m building a “Transactions” table for a user using user_meta array.

I’m new to this and trying to figure things out.

Basically, in practice I know how to store array to user_meta.

JavaScript

My question is how to display ‘transactions’ meta_key for that specific user in a table format like this:

JavaScript

Is it possible to display meta_key array as a loop?

Have no idea how practically do this.

I know it should be possible somehow.

Any help would be very appreciated.

Advertisement

Answer

1- Get all of your users by using get_users function:

JavaScript

2- Create an empty array for the users that have transaction data:

JavaScript

3- Loop through all of your users and pick out those with transaction data and then use array_push to populate $users_with_transaction array:

JavaScript

4- Create your table structure and populate it by looping through the $users_with_transaction array:

JavaScript

Which will output this:

enter image description here

You could then use css to style your table.

This is an example of a table structure with in-line css which gives your table rows borders:

JavaScript

Which will output this:

enter image description here

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement