Skip Navigation

[Resolved] using [wpv-found-count] in a view to feed to a custom field

This support ticket is created 2 years, 9 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)

This topic contains 5 replies, has 2 voices.

Last updated by davelow 2 years, 9 months ago.

Assisted by: Shane.

Author
Posts
#2331759
Screenshot 2022-04-01 at 20.40.22.png
Screenshot 2022-04-01 at 20.39.58.png
Screenshot 2022-04-01 at 20.39.30.png

Tell us what you are trying to do?
I'm trying to feed the value of the "wpv-found-count" of a view to a custom field via shortcodes.
for that the custom field was made to be 'single line' type so that it could be populated with a shortcode.
it appears that wpv-found-count can successfully populate the field with an expected text. (e.g. a number or No items found)
However i cannot meaningfully use the value of the custom field in dynamic string comparisons to conditionally display an elementor element.
for example, if value of custom field is "No items found" conditionally hide element, otherwise display the View

Please let me know if there are ways to reconcile the difference?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#2332059

Shane
Supporter

Languages: English (English )

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

Hi Dave,

Thank you for getting in touch.

Are you saying that when you've added the view code to the custom field value attribute you successfully get an output on the frontend ?

Also you want to compare this field in a condition to hide another field or now ?

Please provide some clarity for me.

Thanks,
Shane

#2334165

Hi Shane,

Thanks for taking this up.

I have a Post Field Group with a number of fields.
I wanted a content template to conditionally display some of the fields. e.g if i do not have any posts that fits some criteria, hide the element which contains the view in the template.

my initial thoughts are to add a new field which counts posts which fits the criteria. the value of this field will be shortcode [wpv-view name=XXX], where xxx is a view which included [wpv-found-count] before the loop. and it does help, although the view probably returned something more than just the value of [wpv-found-count], which was why initially I could not meaningfully set up a condition.

So in the above problem, i managed to work around with the concept 'if field contains text which equals "No items found" ( which illustrates i have no post that fits the criteria), hide the element which contains the view so it does not show up front end'.

for now it looks workable, but i think if there should be a sizable number of posts, will the loop affect the performance of the page?
Is there a way to pass just the value of [wpv-found-count] without looping? or that the loop is essential for [wpv-found-count] to arrive at a value?
In other words, can [wpv-found-count] be used without a view?

much thanks,
Dave

#2334411

Shane
Supporter

Languages: English (English )

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

Hi Dave,

for now it looks workable, but i think if there should be a sizable number of posts, will the loop affect the performance of the page?

It will affect the page performance. I was thinking of a way to limit this but given that you're using the found count then the limit settings on the view will affect the number that is being displayed. Given that the view is just going to list out the found count and not any post data then I dont expect the page performance to decline in any significant way.

Is there a way to pass just the value of [wpv-found-count] without looping? or that the loop is essential for [wpv-found-count] to arrive at a value?

No there isn't the [wpv-found-count] needs to be within the view items found section in order to work. This shortcode cannot function outside of a view.

Thanks,
Shane

#2334521

Thanks your your technical advice Shane.
I will mark this issue as resolved.

#2334525

My issue is resolved now. Thank you!