Problem:
How to only show a Form to submit content if the user hasn't already submitted any (i.e. only allow them to submit one post)?
Solution:
You would need to register a custom shortcode to return the number of posts a user has published to use inside a wpv-conditional shortcode that determined whether the link to the form was displayed or not.
Here is an example of such code:
add_shortcode( 'user-posts', function( $atts = [], $content = null ){ // default is any post type $atts = shortcode_atts( array( 'type' => 'any' ), $atts ); $user_id = get_current_user_id(); $posts = get_posts( array( 'post_type' => $atts['type'], 'post_author' => $user_id, 'numberposts' => -1 ) ); // Return number of published posts return count( $posts ); });
The custom shortcode needs registering at Toolset > Settings > Front-end content to be able to use it for conditions.
The shortcode can be used with or without an attribute to specify the post type, like so:
[user-posts] // Will output the number of posts of any type published by the current user [user-posts type='thing'] // Will output number of posts of post type 'thing'
Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/
https://toolset.com/documentation/adding-custom-code/
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 |
---|---|---|---|---|---|---|
- | 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+00:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 4 months ago.
Assisted by: Nigel.