come ottenere l'elenco di tutti gli utenti e dei loro metadati
-
-
Controlla [questo] (http://wordpress.stackexchange.com/q/36899/43098)Check [this](http://wordpress.stackexchange.com/q/36899/43098)
- 0
- 2016-06-29
- bravokeyl
-
mapoi hobisogno di chiamate diverse 1per l'utente 1peri metadati.Come li combino?but then I need to different calls 1 for user 1 for metadata. How do I combinate them?
- 0
- 2016-06-29
- Hermants
-
E quella chiamata è??And that call is??
- 1
- 2016-06-29
- Hermants
-
3 risposta
- voti
-
- 2016-06-30
Penso che dovresti usare lefunzioni wp-api chefarannotuttoperte.
-
Lafunzione
- get_users () otterràtuttii dati degli utenti semplicemente definendoi campi che urichiedono. Lafunzione
- get_user_meta () otterrài dati di usermeta.
$ utenti=get_users (array ('fields'=> array ('ID'))); foreach ($ users as $ user) { print_r (get_user_meta ($ user-> ID)); } I think you should use wp-api functions which will do everything for you.
- get_users() function will get all users data just define fields which u require.
- get_user_meta() function will get usermeta data.
$users = get_users( array( 'fields' => array( 'ID' ) ) ); foreach($users as $user){ print_r(get_user_meta ( $user->ID)); }
-
Ma questononfarà una queryper utente al database?C'è unmodoperfarlo conmeno query?But will this not make one query per user to the database? Is there any way to do it with fewer queries?
- 1
- 2019-08-17
- Mikael Lindqvist
-
Quando WP recupera un oggetto come un utente/post/termine,preleva ancheil suometae loinseriscein `wp_cache`per ridurreilnumero di querye velocizzare le cose.Quelle chiamate `get_user_meta`nonfaranno query al database,i dati sonogià stati recuperati quando è stato chiamato`get_users`.When WP fetches an object such as a user/post/term it also pre-fetches its meta and puts it in `wp_cache` to reduce the number of queries and speed up things. Those `get_user_meta` calls won't be making database queries, the data was already fetched when `get_users` was called.
- 0
- 2020-06-26
- Tom J Nowell
-
- 2019-11-02
Unmodo unpo 'piùformaleper otteneregli stessi risultati èil seguente Sostituisci qualsiasi ruolo senecessarioe questo codicepresuppone chetu stia utilizzando woocommerceperinformazionipiù dettagliate.
function GetSubscriberUserData() { $DBRecord = array(); $args = array( 'role' => 'Subscriber', 'orderby' => 'last_name', 'order' => 'ASC' ); $users = get_users( $args ); $i=0; foreach ( $users as $user ) { $DBRecord[$i]['role'] = "Subscriber"; $DBRecord[$i]['WPId'] = $user->ID; $DBRecord[$i]['FirstName'] = $user->first_name; $DBRecord[$i]['LastName'] = $user->last_name; $DBRecord[$i]['RegisteredDate'] = $user->user_registered; $DBRecord[$i]['Email'] = $user->user_email; $UserData = get_user_meta( $user->ID ); $DBRecord[$i]['Company'] = $UserData['billing_company'][0]; $DBRecord[$i]['Address'] = $UserData['billing_address_1'][0]; $DBRecord[$i]['City'] = $UserData['billing_city'][0]; $DBRecord[$i]['State'] = $UserData['billing_state'][0]; $DBRecord[$i]['PostCode'] = $UserData['billing_postcode'][0]; $DBRecord[$i]['Country'] = $UserData['billing_country'][0]; $DBRecord[$i]['Phone'] = $UserData['billing_phone'][0]; i++; } return DBRecord; }
At bit more formal way to achieve the same results are as follows Substitute any role as necessary and this code assumes you are using woocommerce for more detailed information.
function GetSubscriberUserData() { $DBRecord = array(); $args = array( 'role' => 'Subscriber', 'orderby' => 'last_name', 'order' => 'ASC' ); $users = get_users( $args ); $i=0; foreach ( $users as $user ) { $DBRecord[$i]['role'] = "Subscriber"; $DBRecord[$i]['WPId'] = $user->ID; $DBRecord[$i]['FirstName'] = $user->first_name; $DBRecord[$i]['LastName'] = $user->last_name; $DBRecord[$i]['RegisteredDate'] = $user->user_registered; $DBRecord[$i]['Email'] = $user->user_email; $UserData = get_user_meta( $user->ID ); $DBRecord[$i]['Company'] = $UserData['billing_company'][0]; $DBRecord[$i]['Address'] = $UserData['billing_address_1'][0]; $DBRecord[$i]['City'] = $UserData['billing_city'][0]; $DBRecord[$i]['State'] = $UserData['billing_state'][0]; $DBRecord[$i]['PostCode'] = $UserData['billing_postcode'][0]; $DBRecord[$i]['Country'] = $UserData['billing_country'][0]; $DBRecord[$i]['Phone'] = $UserData['billing_phone'][0]; i++; } return DBRecord; }
-
- 2020-06-24
Ho creato unplug-in semplicee gratuito,chiamato Flat Meta Data ,che appiattisceposte meta utente datiin un CSV chepuòessere utilizzatopiùfacilmenteper la creazione di reporte l'analisi. Nelprocesso creatabelleneltuo database (
[:prefix]postmeta_flat
e[:prefix]usermeta_flat
) che contengono le stesseinformazionie possonoessere utilizzatein querypiù complesse. Questetabelle hanno una rigaperpost o utentee una colonnaperpunto dati (meta_key) contenentei meta valori (meta_value).Dopo averinstallatoe attivatoilplugin (in wp-content/plugins/flat-table),è accessibiletramite un collegamentonelmenuprincipale delpannello di amministrazione,chiamato Flat Meta Data. È quindipossibilefare clic su & quot; Scaricametadati delpost & quot; o & quot; Scaricametadati utente & quot;pulsantepergenerare latabellae scaricareil CSV contenentetuttii datiin formatofoglio di calcolo.
Alcunenote:
- Questoplug-in vienefornitogratuitamente. Utilizzare aproprio rischio.
- Iprivilegi di CREATE TABLE sono obbligatori. Questonon dovrebbeessere unproblema,mapotrebbeesserlo se hai limitato l'accesso all'utente del database di WordPress.
- Lagenerazionee il download di un set completo dimetadatipuòinfluirenegativamente sulleprestazioni del sistema. Fallo solo durante l'orario di chiusura o,meglio ancora,su una sandboxpopolata coni tuoi datiin tempo reale.
Perfavorefatemi sapere se avete domande. Grazie.
I created a simple, free plugin, called Flat Meta Data, that flattens post and user meta data into a CSV that can more easily be used for reporting and analysis. In the process it creates tables in your database (
[:prefix]postmeta_flat
and[:prefix]usermeta_flat
) that contain the same information and can be used in more complex queries. These tables have one row per post or user and one column per data point (meta_key) containing the meta values (meta_value).After installing and activating the plugin (in wp-content/plugins/flat-table), it is accessible through a link in the main menu of the admin panel, called Flat Meta Data. You can then click on either the "Download post meta data" or "Download user meta data" button to generate the table and download the CSV containing all of the data in spreadsheet form.
A few notes:
- This plugin is provided free of charge. Use at your own risk.
- CREATE TABLE privileges are required. This shouldn't be an issue, but could be if you've restricted access to the WordPress database user.
- Generating and downloading a complete set of meta data can negatively impact system performance. Please do so only during off-hours or, better yet, on a sandbox populated with your live data.
Please let me know if you have any questions. Thanks.
-
Ciaoe Benvenuto!Puoi aggiornare latua rispostaper spiegare comefunziona?Le risposte devonoessere autonome,nonpossonofare affidamentointeramente su linkfuori sede.Hello and welcome! Can you update your answer to explain how it does this? Answers need to be self contained, they can't rely entirely on offsite links.
- 0
- 2020-06-25
- Tom J Nowell
-
Grazieper laguida,Tom.Spero che lemie modifiche siano sufficienti.Perfavorefatemi sapere se avetebisogno di chiarimenti.Thanks for the guidance, Tom. Hopefully my edits suffice. Please let me know if you need any clarification.
- 1
- 2020-06-26
- Tim Burch
-
Ah,ma questo è solo come usareilplug-in :( devi rispondere alla domandae unplug-innon lofa,puoi collegarti a luoghifuori sede come ulteriore lettura o comeesempi,ma la risposta deve contenere la rispostanel suotesto. Il collegamento a unplugin è solo una raccomandazione,non una risposta. Leggendo questonon ho ancoraidea di comeiltuoplugin risolvailproblema,non ci sono dettaglitecnici,il che è unpeccatoperché è un ottimoesempioper dimostrare abilitàtecnichee rispondere alledomandapraticamenteAh but that's just how to use the plugin though :( You need to answer the question, and a plugin doesn't do that, you can link to offsite places as further reading or as examples but the answer needs to contain the answer in its text. Linking to a plugin is just a recommendation, not an answer. Reading this I stll have no idea how your plugin solves ther problem, there's no technical detail, which is a shame because it's a great example to demonstrate technical skill and answer the question practically
- 0
- 2020-06-26
- Tom J Nowell
Comeposso ottenere unelenco dituttigli utenti con ruolo="Clienti",inclusituttii metadatiper utente,significa wp_users + wp_usermeta.
La query di seguitonongenerai risultati desiderati.
Ma l'elenconon è corretto.Mostra ogni utente x voltein base alla quantità di righein wp_usermeta.
Comepossofiltrarlo?Che ogni utentemostriper recordtuttii suoi utenti +i metadati?
Sto ancora cercandoper 6 ore.