How to get its meta_value of a specific meta_key within wp_usermeta

Using the S2member plugin, a meta_key for the last-payment-time is automatically stored in WordPress DB under table wp_usermeta (custom field is called wp_meds2member_last_payment_time).

From wp_usermeta, the column called meta_key has a value 'wp_meds2member_last_payment_time'. But the content I'm trying to collect is its meta_value equivalent.

I didn't find how to call this meta_value to the function below where I use the date of the last payment time to start a new count of the posts created by the user.

function check_post_limit(){
   if(current_user_can('edit_posts')) {
   global $userdata;
   global $post_type;
   global $wpdb;
   $postintervall = date('Y-m-d H:i:s', $s2member_last_payment_time );
   $item_count = $wpdb-get_var( "SELECT count(*) FROM $wpdb-posts WHERE post_status = 'publish' AND post_author = $userdata-ID AND post_date  '$postintervall'" );
    if(( $item_count = 2 )  (current_user_is("s2member_level1")) )
  { wp_die( 'Do not create too much posts.','check-limit' ); }

return;   }
}

Any suggestions? Thanks

Topic s2member meta-value user-meta date-time Wordpress

Category Web


@Cristián Lávaque Thank you for the hints ;)

Actually I managed to resolve the issue blocking this function (show the hidden comment above). In case this would help anyone here is the final working code:

function check_post_limit() {
    if ( current_user_can( 'edit_posts' ) ) {
        global $userdata;
        global $wpdb;
        $s2member_last_payment_time = get_user_meta( get_current_user_id(), 
            'wp_s2member_last_payment_time', true );
        $postintervall = date( 'Y-m-d H:i:s', $s2member_last_payment_time );
        $item_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts 
            WHERE post_status = 'publish' AND post_author = $userdata->ID 
            AND post_date > '$postintervall'" );
        if ( ( $item_count >= 2 ) && ( current_user_is( "s2member_level1" ) ) ) { 
            wp_die( 'Do not create too much posts.', 'check-limit' ); 
        }
        return;   
    }
}

@Amine, the meta field's name is just s2member_last_payment_time, so try it without the wp_med prefix and see if that works.

$2member_last_payment_time = get_user_meta(get_current_user_id(), 's2member_last_payment_time', true);

You can also try s2Member's function get_user_field: http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field%28%29

$s2member_last_payment_time = get_user_field ('s2member_last_payment_time');

If no payment actually happened, then no payment time would be recorded, but if there is it'll be a timestamp.

I hope that helps. :)

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.