Last active
December 25, 2023 20:19
-
-
Save MjHead/c9a77e0101746920055c0a8071445529 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'jet-engine/listings/macros-list', 'jet_register_custom_macros' ); | |
| /** | |
| * Add new macros to default macros list | |
| * | |
| * %business_users% - macros name | |
| * | |
| */ | |
| function jet_register_custom_macros( $macros_list ) { | |
| $macros_list['business_users'] = 'jet_get_business_users'; | |
| return $macros_list; | |
| } | |
| /** | |
| * Macros callback function | |
| */ | |
| function jet_get_business_users( $field_value ) { | |
| $users = array(); | |
| $post_id = get_the_ID(); | |
| // You need to replace this with your actual meta key | |
| $meta_key = 'user-business'; | |
| global $wpdb; | |
| $query = "SELECT user_id FROM $wpdb->usermeta WHERE `meta_key` = '$meta_key' AND `meta_value` = $post_id"; | |
| $res = $wpdb->get_results( $query, 'ARRAY_A' ); | |
| if ( ! empty( $res ) ) { | |
| foreach( $res as $user ) { | |
| $users[] = $user['user_id']; | |
| } | |
| } | |
| if ( empty( $users ) ) { | |
| $users[] = 'not-found'; | |
| } | |
| return implode( ',', $users ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter( 'jet-engine/listings/macros-list', 'jet_register_custom_macros' ); | |
| /** | |
| * Add new macros to default macros list | |
| * | |
| * %business_users% - macros name | |
| * | |
| */ | |
| function jet_register_custom_macros( $macros_list ) { | |
| $macros_list['business_users'] = 'jet_get_business_users'; | |
| return $macros_list; | |
| } | |
| /** | |
| * Macros callback function | |
| */ | |
| function jet_get_business_users( $field_value ) { | |
| $users = array(); | |
| $post_id = get_the_ID(); | |
| // You need to replace this with your actual meta key | |
| $meta_key = 'user-business'; | |
| global $wpdb; | |
| $query = "SELECT user_id FROM $wpdb->usermeta WHERE `meta_key` = '$meta_key' AND `meta_value` LIKE '%\"$post_id\"%'"; | |
| $res = $wpdb->get_results( $query, 'ARRAY_A' ); | |
| if ( ! empty( $res ) ) { | |
| foreach( $res as $user ) { | |
| $users[] = $user['user_id']; | |
| } | |
| } | |
| if ( empty( $users ) ) { | |
| $users[] = 'not-found'; | |
| } | |
| return implode( ',', $users ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment