Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter wpuseraccount

    (@wpuseraccount)

    Thank you very much.

    I did not know the global variable $post_type.
    I looked into the global variable.
    There was a lot of useful global variables.
    I study more.
    I am very grateful to you.

    Thank you.

    Thread Starter wpuseraccount

    (@wpuseraccount)

    Thank you.

    I am very grateful to Namita and Subharanjan.

    [Bainternet Posts Creation Limits] is very good.
    This limits the post per day.
    But, this does not limit the post per hour or forever.

    I’ve tried the following methods.
    If possible, I want to check this.

    What good does the admin_head-post-new.php is use ?
    Is the SQL wrong ?

    Please, I want to check.
    I’m sorry about I can only do a little English.

    ———- functions.php ———-

    add_action( 'admin_head-post-new.php', 'check_post_limit' );
    function check_post_limit() {
      if( $_GET['post_type'] === 'item' ) {
        global $userdata;
        global $wpdb;
        $item_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'item' AND post_author = $userdata->ID" );
        if( $item_count >= 12 ) { wp_die( "error" ); }
      } elseif( $_GET['post_type'] === 'shopinfo' ) {
        global $userdata;
        global $wpdb;
        $shopinfo_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'shopinfo' AND post_author = $userdata->ID" );
        if( $item_count >= 1 ) { wp_die( "error" ); }
      } elseif( $_GET['post_type'] === 'news' ) {
        global $userdata;
        global $wpdb;
        $today = date( 'Y-m-d 00:00:00', ( gmmktime() );
        $news_count = $wpdb->get_var( "SELECT count(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'news' AND post_author = $userdata->ID AND post_modified > '$today'" );
        if( $news_count >= 10 ) { wp_die( "error" ); ]
      }
    }

    [Moderator Note: Please post code or markup snippets between backticks or use the code button. As it stands, your code may now have been permanently damaged/corrupted by the forum’s parser.]

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