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
get_user_meta
function like$s2member_last_payment_time = get_user_meta( get_current_user_id(), 'wp_meds2member_last_payment_time', true );
? codex.wordpress.org/Function_Reference/get_user_metaget_user_meta
function check_post_limit(){ if(current_user_can('edit_posts')) { global $userdata; global $post_type; global $wpdb; $s2member_last_payment_time = get_user_meta( get_current_user_id(), 'wp_meds2member_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( 'Too much posts.', ); }return;}}
if( (current_user_can('edit_posts')) && ( $post_type === 'course' ))
and at the count of the posts (courses)item_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_author = $userdata->ID AND post_type = 'course' AND post_date > '$postintervall ' " );
. When I deleted the check in the condition of the function it works. Thank you !!