Skip Navigation

[Resolved] limit custom post type creation

This thread is resolved. Here is a description of the problem and solution.

Problem: I have a Form that creates posts. If a certain number of posts have been created, I would like to hide the Form.

Solution: Use a View to count the number of results. Use a conditional inside the View to show or hide the Form based on that number of posts.

[wpv-layout-start]
    [wpv-items-found]
[wpv-conditional if="( '[wpv-found-count]' lt '3' )"]
less than 3 posts found - include the Form shortcode here
[/wpv-conditional]
  
[wpv-conditional if="( '[wpv-found-count]' gte '3' )"]
number of posts is greater than or equal to 3, do not include the Form shortcode here.
[/wpv-conditional]
    <!-- wpv-loop-start -->
    <wpv-loop></wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]no posts found - include the Form shortcode here[/wpv-no-items-found]
[wpv-layout-end]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 5 years, 4 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 4 replies, has 2 voices.

Last updated by ericW-5 5 years, 4 months ago.

Assisted by: Christian Cox.

Author
Posts
#1349231

Tell us what you are trying to do?
I would need to limit custom post type creation for a specific custom post type (e.g. "projet-page-accueil") sitewide, i.e. all users could not create a new post with my front end form when a certain number of active posts is reached, say 3 posts.

What is the link to your site?
hidden link

#1349339

Hi, one way you can achieve this is by using a View to determine whether or not to display the Form. Set up a View to show all the posts in that custom post type with a maximum limit of 3 posts. Then in the Loop Editor of this View, use conditional HTML to show or hide the Form based on the wpv-found-count shortcode.

[wpv-conditional if="( '[wpv-found-count]' lt '3' )"]
less than 3 posts found - include the Form shortcode here
[/wpv-conditional]

[wpv-conditional if="( '[wpv-found-count]' gte '3' )"]
number of posts is greater than or equal to 3, do not include the Form shortcode here.
[/wpv-conditional]

https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count

#1349359

Hi
thanks a lot for this answer.

In fact I want to show or hide the form on another page than the one displaying all the posts ?
I display these custom posts on the home page but the form is on another page. Is it possible to limit the post creation in this case ?

Thanks in advance

#1349397

In fact I want to show or hide the form on another page than the one displaying all the posts ?
Yes, that's fine. It can be a separate View. You can remove all the information from the View's loop and display nothing for each post. There is no list of posts visible.

[wpv-layout-start]
	[wpv-items-found]
[wpv-conditional if="( '[wpv-found-count]' lt '3' )"]
less than 3 posts found - include the Form shortcode here
[/wpv-conditional]
 
[wpv-conditional if="( '[wpv-found-count]' gte '3' )"]
number of posts is greater than or equal to 3, do not include the Form shortcode here.
[/wpv-conditional]
	<!-- wpv-loop-start -->
	<wpv-loop></wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]no posts found - include the Form shortcode here[/wpv-no-items-found]
[wpv-layout-end]
#1349417

My issue is resolved now. Thank you!