Custom Fields
Re-Envisioned
Support MB User Meta User query for timestamp in meta array whne less than today's date

  • Creator
    Topic
  • #26558
    Resolved rubbergumball
    Participant

    I've given access to content my site by adding meta values to user data using the MB User Meta. The data I need to access is a timestamp, one of two items in an array for that user (the other is the product) and they can have multiple products with different timestamps. Timestamps are used to determine when access is removed.

    How would I query and return the timestamp for all users if timestamp is less than today? I would like to remove access if the timestamp is less than today.

    this is an example of the data stored in Database for the meta field "product_data":
    a:2:{i:0;a:2:{s:14:"product_access";s:3:"prd2";s:15:"acc_expiry_date";i:1618779456;}i:1;a:2:{s:14:"product_access";s:3:"prd2";s:15:"acc_expiry_date";i:1618779456;}}

    this is my current code to return the users but it doesn't return any results:

    <?php
    $date = new DateTime();
    $theDate = $date->getTimestamp();
    
    $user_query = new WP_User_Query( 
        array( 
            'product_data' => 'acc_expiry_date', 
            'meta_value' => '$theDate', 
            'meta_compare' => '<' 
            ) 
        );
            
    // The User Query
    $user_query = new WP_User_Query( $args );
    
    // The User Loop
    if ( ! empty( $user_query->results ) ) {
        foreach ( $user_query->results as $user ) {
            // change meta go here after success test
            $user_info = get_userdata($user->ID);
            echo '<li>' . $user_info->first_name . ' ' . $user_info->last_name . '</li>';
        }
    } else {
        // no users found
    }
    ?>

    Thanks!
    Scott

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.