Skip Navigation

[Closed] Output Content based on whether the user has completed CRED forms

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 12 replies, has 2 voices.

Last updated by Shane 7 years, 6 months ago.

Assisted by: Shane.

Author
Posts
#433719
CONDITIONAL OUPTUT BASED ON POST TYPE CREATION.PNG

I am trying to: Show "Complete" Beside a link to a form when the user has completed that form

I visited this URL: hidden link

I expected to see: Please Complete Your Basic Info & Work History Questionnaire COMPLETE

Instead, I got:
Please Complete Your Basic Info & Work History Questionnaire

#433750

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Thank you for contacting our support forum.

For this you will need a custom shortcode to check if the user has already submitted the form. Since this is a CRED form a post is created whenever the form is submitted by that user. So all we need to do is check if the user has a post under that post type.

Add the following to your functions.php file

// Add Shortcode
function count_my_posts( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'user_id' => '',
			'posttype' => '',
		),
		$atts
	);

	 return count_user_posts( $atts['user_id'] , $atts['posttype'] );

}
add_shortcode( 'count_my_posts', 'count_my_posts' );

Then you can use this shortcode by doing this [count_my_posts user_id='[wpv-current-user info="lastname"]'] posttype='post_type_slug' ]

Finally you can then use our conditional setup in order to conditionally display the text whether the user has posts or not.

Please let me know if this helps.
Thanks,
Shane

#433763
testing shanes shortcode.PNG

Hi Shane,

Thanks so much for helping.

I've added the code to the functions file ok and after editing the code above to remove the extra ] I have the shortcode working ok (see new screenshot or hidden link)

But it's showing 0 I'm logged in as the admin so should have plenty of posts, do I need to pass the function a user ID?

Also how do i then call this data using the conditional GUI?

Again, really appreciate your help, thanks again.

#433771

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Change the shortcode to .

 [count_my_posts user_id='[wpv-current-user info="id"]'] posttype='post_type_slug' ]

You will need to use the instructions below in order to evaluate shortcodes inside our wpv-conditional shortcode.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

Please let me know if this helps.
Thanks,
Shane

#433780
CONDITIONAL OUTPUT WITH SHORTCODE SYNTAX ISSUE.PNG

Sorry Shane, It's late for me so I'm probably making a simple mistake here, but after following the instruction to add a shortcode and use it in a condition I'm still not sure what I'm doing wrong.
the page is displaying: '<' 0"] COMPLETE1 [/wpv-conditional]

Please see screenshot, I created 4 examples to test the syntax and have one showing, but not how I think it should?

Again really appreciate the super fast support 🙂

#433789

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Try this 🙂

[wpv-conditional if="( '[wpv-current-user info="lastname"]'] posttype='post_type_slug' ]' gt '0' )"]
Content here
[/wpv-conditional]

This should help 🙂

Thanks,
Shane

#434000
CONDITIONAL OUTPUT WITH SHORTCODE SYNTAX ISSUE2.PNG

That outputs nothing - Can you explain the snippet so I can understand how it is supposed to work?

Many thanks,

D

#434155

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

I feel embarrassed 🙁 I paste the same code twice

It should be

[wpv-current-user info="id"]

This would get the ID of the current user.

Try only this and it should return a number.

[wpv-current-user info="id"]'] posttype='post_type_slug' ]

Thanks,
Shane

#434169
showing data and slug.PNG
CONDITIONAL OUTPUT WITH SHORTCODE SYNTAX ISSUE3.PNG

No output.
Here's what I have on the page:
[wpv-conditional if="( '[wpv-current-user info="id"]'] posttype='applic-personal-info' ]' gt '0' )"]
Content here
[/wpv-conditional]

So we're checking to see if the current user has completed any posts with the slug applic-personal-info, then (I'm guessing here) we are asking if the count is greater than 0 to then display "Content Here"

I've added an applic-personal-info post, I'm the author, I'm the logged in user.
I've checked the registered shortcodes [count_my_posts] is registered ok
I've added

// Add Shortcode
function count_my_posts( $atts ) {

// Attributes
$atts = shortcode_atts(
array(
'user_id' => '',
'posttype' => '',
),
$atts
);

return count_user_posts( $atts['user_id'] , $atts['posttype'] );

}
add_shortcode( 'count_my_posts', 'count_my_posts' );

To my functions file

I'm not seeing "content Here"

Whats next buddy?

#434235

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Mind allowing me to have admin access to have a look ?

The private fields will be enabled for your next response.

Thanks,
Shane

#434682

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

Since this is a production site I would rather not interfere with it. However i went ahead and perform some tests and it worked for me.

Try this code


[wpv-conditional if="( '[count_my_posts user_id='[wpv-current-user info="id"]' posttype='post' ]' gt '0' )"]

This is my post count = [count_my_posts user_id='[wpv-current-user info="id"]' posttype='post' ]



[/wpv-conditional]

I forgot to mention that in order for this to work in our wpv-conditional you need to add the shortcode name to our Views 3rd party shortcode arguments .

To do this go to Settings -> Frontend content and add count_my_posts to the 3rd party shortcode arguments.

Once you have done this then it should work now.

Please let me know if this helps.
Thanks,
Shane

#435269

Shane apologies, I gave you access to the wrong install

I have updated the credentials above.

Whilst the code you provided works, it does not do what I asked for, namely check posts and modify output based on whether they are there or not - can you suggest how I use your solution to do that ?

Also - some posts and comments disappeared from the /admiralbook install I had given you access to - did you have to do a DB restore? it's ok, I just need to know.

Thanks David

#435338

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi David,

I might have missinterpret your initial post.

What I had in mind is that each user can only complete the questionnaire only once. This means that the code will check if the user created a post of that post type and then not display the questionnaires again.

Is this the intention?

Also I didn't log into the website as it was a production site. All tests were done on my localhost.

Thanks
Shane

The topic ‘[Closed] Output Content based on whether the user has completed CRED forms’ is closed to new replies.