Home Forums Plugin Support WP User Frontend Pro User Meta as default value and limit post creation

This topic is: not resolved

This topic contains 4 replies, has 4 voices, and was last updated by  joshi 4 years, 3 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #5317

    MarkGray
    Participant
    Post count: 3

    Hi, I'd like to have a users display name as the default value of a post-title field in a custom post type and to have the post-title field hidden on the WP User Frontend form used to create the post. So basically, when a user creates a post of this post type the title is automatically filled with their display name.

    I was also wondering if it was possible to limit the number of post creations to 1.

    Cheers

    Mark

    #5321

    Tareq Hasan
    Keymaster
    Post count: 2831

    This php snippet will allow to post only who has less than 1 post.

    [php]
    function wpufe_limit_post_one( $user_can_post ) {
    if ( count_user_posts( get_current_user_id() ) < 1 ) {
    return ‘yes';
    }

    return ‘no';
    }

    add_filter( ‘wpuf_can_post', ‘wpufe_limit_post_one' );
    [/php]

    And this one will set the post title as the display name.
    [php]
    function wpufe_set_disply_name( $post_id ) {
    $post_title = get_post_field( ‘post_title', $post_id );

    wp_update_user(array(
    ‘ID' => get_current_user_id(),
    ‘display_name' => $post_title
    ));
    }

    add_action( ‘wpuf_add_post_after_insert', ‘wpufe_set_disply_name' );
    [/php]

    Insert them to your themes functions.php and should work.

    #5324

    MarkGray
    Participant
    Post count: 3

    Thanks Tareq for your speedy response. I will try these out.

    #24810

    Denis
    Participant
    Post count: 165

    hello,
    how can i limit it to my custom post type “artist”

    function wpufe_limit_post_one( $user_can_post ) {
        if ( count_user_posts( get_current_user_id() ) < 1 ) {
            return 'yes';
        }
     
        return 'no';
    }
     
    add_filter( 'wpuf_can_post', 'wpufe_limit_post_one' );

    cheers,
    denis

    #35890

    joshi
    Member
    Post count: 18

    Hello,

    As my previous poster, I also wanted to know how to limit a custom post type.

    Thank you.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘User Meta as default value and limit post creation’ is closed to new replies.