Ecommerce Shopify WordPress Discussion

get user meta by user id in wordpress

I update Many Meta in current user and i want get all of meta <?php $new_user_id = 1 ; $stats = test; update_user_meta( get_current_user_id() , 'add-user-id-'.$new_user_id, $stats); $new_user_id = 2 ; $stats = test; update_user_meta( get_current_user_id() , 'add-user-id-'.$new_user_id, $stats); ?> Run code snippetExpand snippet How can I get Any Meta Like 'add-user-id-[array of all users id ]' ? Example : I want List Of all Users Id saved in current user
From the current user ID you can get all its related metadata with get_user_meta() like: // Get all user metadata in an array $user_meta = get_user_meta( get_current_user_id(), false, true ); // Display the metadata array echo '<pre>'. print_r( $user_meta, true ) . '</pre>';

February 26, 2024

You can get all user_meta and then find the ones you need. For example, something like this: $new_user_id = 1 ; update_user_meta( get_current_user_id(), "add-user-id-$new_user_id", $new_user_id ); $new_user_id = 2 ; update_user_meta( get_current_user_id(), "add-user-id-$new_user_id", $new_user_id ); $find_meta_ids = [1, 2]; $find_key_prefix = 'add-user-id-'; $output = []; $all_meta = get_user_meta( get_current_user_id() ); foreach ( $all_meta as $key => $value ) { $key_id = array_pop( explode( $find_key_prefix, $key ) ); if( in_array( $key_id, $find_meta_ids ) ) { $output[$key] = $value[0]; } } var_dump( $output ); Result: array(2) { ["add-user-id-1"]=> string(1) "1" ["add-user-id-2"]=> string(1) "2" }

February 26, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.