Limit listings of certain CPTs to 1 per user

This topic contains 21 replies, has 5 voices, and was last updated by  Alex Howes 6 years, 7 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: ,

  • Author
    Posts
  • #429485

    Alex Howes
    Expired Member
    Post count: 175

    Thanks Kiran, it’s still not working though

    #429488

    Dirk
    Full Member
    Post count: 390

    @alex,

    I’m always using geodir_get_current_posttype() to get the post type of GD CPTs. I never had problems with the function call.

    So in your case the code will be:

    
    
    if (geodir_get_current_posttype() == 'gd_cv') {
      ...

    Best,
    Dirk

    #429489

    Alex Howes
    Expired Member
    Post count: 175

    Thanks Dirk, I’ve changed it to that and it’s still not working. If I remove the if statement completely it works, so it must be a problem with getting the post type.

    #429490

    Dirk
    Full Member
    Post count: 390

    Are you sure that the CPT naming is correct? Could you check please:
    GD – Custom Post Types. There you can find the post type.

    #429495

    Alex Howes
    Expired Member
    Post count: 175

    Hi Dirk, yes, the post_type is ‘gd_cv’. You can see it in the JSON file here under “type” http://www.barn-door.co.uk/wp-json/geodir/v1/cvs.

    #429496

    Kiran
    Moderator
    Post count: 7069

    Hi Alex,

    Try this one

    
    
    function change_user_role_when_submit_cv( $maybe_empty, $postarr ) {	
    	if ( $postarr['post_type'] =='gd_cv' ) {
    		$current_user = wp_get_current_user();
    		$current_user_roles = $current_user->roles;
    
    		if ( in_array( 'um_worker', $current_user_roles ) ){
    			$current_user->set_role( 'worker_has_cv' );
    		}
    	}
    	return $maybe_empty;
    }
    add_filter( 'wp_insert_post_empty_content', 'change_user_role_when_submit_cv', 10, 2 );

    Kiran

    #429497

    Alex Howes
    Expired Member
    Post count: 175

    Hi Kiran, I’ve just got it to work using this:

    
    
    add_action('geodir_after_save_listing', 'change_user_role_when_submit_cv');
    
    function change_user_role_when_submit_cv( $last_post_id, $request_info ) {
      
      if (geodir_get_current_posttype() == 'gd_cv') {
    	
    	$current_user = wp_get_current_user();
    	$current_user_roles = $current_user->roles;
    	
    	if (in_array('um_worker', $current_user_roles)){
    	  
    	  	$current_user->set_role( 'worker_has_cv' );
    	}
      
      }
    }

    Thanks for your help with this 🙂

Viewing 7 posts - 16 through 22 (of 22 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
20% Discount Offer
Hurry! Get your 20% discount before it expires. Get 20% Discount