Skip Navigation

[Resolved] Hide/Show content based on conditional, but limit the number of displayed posts

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

Problem:

limit the number of posts created by a user containing the option 'On' to 3.

Solution:

It is possible with a post view + a post form, for example:

https://toolset.com/forums/topic/hide-show-content-based-on-conditional-but-limit-the-number-of-displayed-posts/#post-1787327

Relevant Documentation:

This support ticket is created 4 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Jaime 4 years, 4 months ago.

Assisted by: Luo Yang.

Author
Posts
#1785743
1294823-screenshot_.jpg

Tell us what you are trying to do?
I have users publishing posts. I would like to offer them the option to Show or Hide those posts and I thought it would be a good way to do it inserting a Switch button on their posts and displaying those posts conditionally the using the [wpv-conditional] shortcode.

To do this, I would insert a field on posts with two options ( On / Off ) and I'll output conditionally those posts marked with 'On'.
So far, I think I got it.

But, my question is:
I want to limit the number of displaying posts to three (no more, but maybe less).
So, there is a way to limit the number of posts with the 'On' option selected to three?

I'm no t sure if this is possible.
This is not an urgent question for me, if there are other users with urgent questions, please feel free to provide help them first.

#1787005

Hello,

I think it is possible, for example, you can try these:
1) Create a custom radio field "Show or Hide", with two options:
- On
- Off
https://toolset.com/course-lesson/creating-custom-fields/

2) Create a post view:
- Query posts of your custom post type
- Filter by "Show or Hide" field is On
- Display only 3 items
https://toolset.com/course-lesson/creating-a-view/

#1787215

I Luo. Thanks for your answer.
That's exactly what I'm doing right now.

But in this case, user can have 4 posts with the 'On' option selected, despite only 3 posts will be displayed. That's what I'm trying to avoid, because it seems strange to me to have 4 options in 'On', but only 3 of them displayed.

So, what I'm looking for is more like: limit the number of posts created by a user containing the option 'On' to 3.

Probably it's not a common situation and it's not possible so easy.
Please, Luo, if this is a difficult issue for you, let me know.
Still it's not urgent for me.

Thanks again!

#1787327

It is possible with a post view + a post form, for example, your can try these:

1) Create a post form for creating new custom post

2) Create a post view:
- Query posts of your custom post type
- Filter by:
"Show or Hide" field is On
Post author is same as current logged-in user
- Display only 3 items

In section "Loop Editor", you can get total post counts with shortcode [wpv-found-count]:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-found-count

Use above shortcode in [wpv-conditional] shortcode to check if [wpv-found-count] is lower than 3, then display the form shortcode of step 1)

#1788861

My issue is resolved now. Thank you!