User Meta as default value and limit post creation

This topic contains 4 reply and 4 voices, and was last updated by joshi 9 years, 2 months ago
Viewing 4 Posts - 1 through 4 (of 4 total)
Author Posts
June 27, 2013 at 11:57 am 5317
joshi 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
June 27, 2013 at 2:01 pm 5321
Tareq Hasan Tareq Hasan

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.

June 27, 2013 at 2:08 pm 5324
MarkGray MarkGray

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

August 8, 2014 at 8:34 pm 24810
Denis Denis

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

February 5, 2015 at 8:56 pm 35890
joshi joshi

Hello,

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

Thank you.

Viewing 4 Posts - 1 through 4 (of 4 total)