Title: Sync using user meta
Last modified: July 17, 2017

---

# Sync using user meta

 *  Anonymous User 7276204
 * (@anonymized-7276204)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/sync-using-user-meta/)
 * Hi, I am using User Meta Pro (which creates custom meta data in the wp_usermeta
   table).
 * I have a custom field called “newsletter” which is just a checkbox.
 * I want to use the filter provided in the plugin docs to sync only those who have
   checked that they want to receive newsletters.
 * I believe the easiest way to do this is just by saying to sync where `$newsletter`
   is not empty:
 *     ```
       add_filter( 'mailchimp_sync_should_sync_user', function( $subscribe, $user ) {
   
           // check for custom user field
           if( !empty( $newsletter ) ) {
               return true;
           }
   
           // do not subscribe otherwise
           return false;
       });
       ```
   
 * However, this doesn’t seem to be working. In the “Status” pane in the backend
   I get 0/xxxx indicating to me that it does not find anyone matching those criteria.
 * What am I doing wrong here?
 * Thank you.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Contributor [Lap](https://wordpress.org/support/users/lapzor/)
 * (@lapzor)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/sync-using-user-meta/#post-9344136)
 * Where are you loading the custom user field into the $newsletter variable?
    I
   think you should find it somewhere in $user. Maybe you can dump $user and take
   a look in there?
 * Hope that helps,
 *  Thread Starter Anonymous User 7276204
 * (@anonymized-7276204)
 * [8 years, 10 months ago](https://wordpress.org/support/topic/sync-using-user-meta/#post-9346978)
 * Still not working, I played around with the code a bit using snippets from Github
   and currently have this:
 *     ```
       add_filter( 'mailchimp_sync_should_sync_user', function( $sync, $user ) {
   
           // create array of users 
   
           $subscribed = new WP_User_Query( array( 'meta_key' => 'newsletter' ) );
   
           // check for custom user field
   
           if ( ! empty( $subscribed->results ) ) {
       	foreach ( $subscribed->results as $user ) {
               	return $sync;
       	}
           }
   
           // do not subscribe otherwise
           return false;
       });
       ```
   
 * I’ve also tried with `$subscribe` instead of `$sync` but it’s not working.
 * I dumped the contents of my array in a test, and it does return the users that
   have subscribed, so the plugin should be finding them… I’m not sure what I’m 
   doing wrong exactly.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Sync using user meta’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/mailchimp-sync_cfeefa.svg)
 * [MC4WP: Mailchimp User Sync](https://wordpress.org/plugins/mailchimp-sync/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/mailchimp-sync/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/mailchimp-sync/)
 * [Active Topics](https://wordpress.org/support/plugin/mailchimp-sync/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/mailchimp-sync/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/mailchimp-sync/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: Anonymous User 7276204
 * Last activity: [8 years, 10 months ago](https://wordpress.org/support/topic/sync-using-user-meta/#post-9346978)
 * Status: not a support question