Skip Navigation

[Resolved] Editing content-submission forms

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 6 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 10 replies, has 2 voices.

Last updated by andreaD-4 6 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#541120

Hello, I created a custom post where only registered users can add a post through CRED form. I would like a user after login to add this form and afterwards can only modify it but can not add a new form.
I can not edit the post that a single user adds.
here there is example
hidden link

Thanks

#541364

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andrea

I'm not sure I have understood your question correctly.

You have a custom post type, and a CRED form to publish custom posts and a CRED form to edit them.

You want registered users to be able to publish one custom post, and only one, is that correct? If they have already published their one custom post they should be able to edit it, but not publish a new one.

Have I understood the question correctly?

#541450

yes. If you need credentials to get into the backend I can send them.

#541485

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andrea

You'll need to use some custom code, which I can help you with if you need it.

Here is how I see it working, if you agree I can write the code.

You have a page which will display either the create post form or the edit post form for the currently logged in user.

It will include conditional shortcodes which test if the current user already has a post published, in which case it will return the ID of the post so that the edit form knows which post to edit. If there are no posts then it will display the add post form instead.

Does that sound right? What is the slug of your custom post type?

#541488

Yes,
Thanks to many Nigel,
the slug is consulenti.

thank you

#541949

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andrea

Here is the custom shortcode you will need to add to your site (add this code to your theme's functions.php file at the end, or use a plugin such as Code Snippets to add it):

/**
 * Custom shortcode to return ID of consultant post
 * authored by current user
 */
add_shortcode( 'consultant-id', function(){

	$consultant_id = 0; 

	$user = wp_get_current_user();

	if ( $user->ID != 0 ) {

		// get consultant posts authored by current user
		$args = array(
			'post_type'		=>	'consulenti',
			'post_status'	=>	'publish',
			'author'		=>	$user->ID
		);
		$consultant_posts = get_posts( $args );

		if ( !empty($consultant_posts) ) {
			$consultant_id = $consultant_posts[0]->ID;
		}
	}

	return $consultant_id;

});

Note that I have been using consultant in the above—which you are welcome to edit—although the post type slug used is consulenti.

You will first need to register the shortcode "consultant-id" at Toolset > Settings > Front-end Content for use in Views shortcodes.

The shortcode checks to see whether the current user is the author of any consulenti posts, and if yes it returns the id of the post, and if not it returns zero.

So we can add a CRED new post and CRED edit post form to the same page inside conditional shortcodes, like so:

[wpv-conditional if="( '[consultant-id]' eq '0' )"]
[cred_form form='publish-consultant' form_name='Publish Consultant']
[/wpv-conditional]

[wpv-conditional if="( '[consultant-id]' ne '0' )"]
[cred_form form='edit-consultant' form_name='Edit Consultant' post='[consultant-id]']
[/wpv-conditional]

I tested this on a local site and it worked, but if you have any problems let me know.

#542059

Hi Nigel, thank you for your precious help.
When a user posts a custom post the status is in pending review. The administrator changes status in published and after the user can edit the custom post.
When the status is pending the user can only read a text (please wait, for example) then when the stauts change, he can edit his post.
How can I do this?
When does status change from pending review to published, is there a way to send an email automatically to the user?
thank you

#542497

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Andrea

I modified the shortcode so that it returns 0 if there are no existing posts, the post id if there is a published post, and -1 if there is an existing pending post.

/**
 * Custom shortcode to return ID of consultant post
 * authored by current user
 */
add_shortcode( 'consultant-id', function(){

	$consultant_id = 0; 

	$user = wp_get_current_user();

	if ( $user->ID != 0 ) {

		// get consultant posts authored by current user
		$args = array(
			'post_type'		=>	'consulenti',
			'post_status'	=>	array('publish','pending'),
			'author'		=>	$user->ID
		);
		$consultant_posts = get_posts( $args );

		if ( !empty($consultant_posts) ) {
			$consultant_id = ( $consultant_posts[0]->post_status == 'publish' ) ? $consultant_posts[0]->ID : -1;
		}
	}

	return $consultant_id;

});

You will also need to modify the conditional shortcodes to cater for the 3 possibilities, something like this:

[wpv-conditional if="( '[consultant-id]' eq '0' )"]
[cred_form form='publish-consultant' form_name='Publish Consultant']
[/wpv-conditional]

[wpv-conditional if="( '[consultant-id]' lt '0' )"]
<p>You're post is pending review</p>
[/wpv-conditional]

[wpv-conditional if="( '[consultant-id]' gt '0' )"]
[cred_form form='edit-consultant' form_name='Edit Consultant' post='[consultant-id]']
[/wpv-conditional]

That should do the trick.

You can create automatic notification emails when the post status is changed, see https://toolset.com/documentation/user-guides/automated-email-notifications-with-cred/

However, note the following caveat. The emails will only be triggered when the change happens via a CRED form. If you change the post status in the back end the notification will not be sent. You need to use a CRED edit form which includes a selector for the post status and use that to change the status and trigger the email.

#542735

Hi Nigel, Thank you everything works 🙂
Sorry but I did not understand how to create a CRED to give the administrator the ability to change the status of the custom post that by pending will be changed to pubblished. Can you give me an example please?

#542893

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Screen Shot 2017-06-29 at 10.07.41.png

Hi Andrea

You would make a normal CRED Edit form and in the settings you would set the status to Published (see screenshot). The form wouldn't need to contain much of anything apart from the submit button.

You could display the form to administrators when viewing the post on the front end.

#544367

thank you

The forum ‘Types Community Support’ is closed to new topics and replies.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.