Skip Navigation

[Resolved] Show how many custom fields that has a specific value

This support ticket is created 5 years, 5 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 8 replies, has 2 voices.

Last updated by Luo Yang 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#1311849

I would like to show a count of how many of my custom fields that has the spesific value of "no"

There are several fields where you have to choose between yes or no. I would like to show how many unike fields that has the value "no" (raw value 2)

I have tried to add multiple filters, and tested both OR and AND - but I am not able to show the total numbers of "no" entries.

#1311941

Hello,

I suggest you follow our document to setup a post view:
- Filter by the custom fields is specific value:
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
If you need to get results satisfied with both conditions, you will need to use "AND" logic.
- Output the post found count shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-found-count

#1311989

Hi,
I dont Get this to work.

I would like to show the total count of multiple custom fields.

#1312015

There isn't such kind of built-in feature for showing the total count of multiple custom fields, the approach I mentioned above:
https://toolset.com/forums/topic/show-how-many-custom-fields-that-has-a-specific-value/#post-1311941
I can only show post found count, but it should be able to work too.

If need more help for it, please provide a test site with the same problem, also point out the problem page URL and view URL, I need to test it in a live website, thanks

#1312805

I think there is a misunderstand, I assume you are going to count the user's inputs of Toolset post form in front-end.

If it is, those user's inputs have not been saved into database yet, so Views plugin won't be able to work here.

It needs custom JS codes, according to our support policy, we don't provide custom codes support:
https://toolset.com/toolset-support-policy/

Since you have already provided your website credentials, I can setup a demo for you.
Here are detail steps:
1) Edit the post form "El - registrering av ny":
hidden link
in section "Form editor", change line 11 from:

<div class="row">

To:

<div class="row generelle-forhold">
  	<div style="background-color:green"><span class="wpcf-el-gen-1-ikke-kontrollert">0</span> Ikke kontrollert</div>

- Add a CSS class name "generelle-forhold" to that row DIV tag
- Add a green HTML div tag to display the count result

2) Click "JS Editor", add below JS codes:

jQuery(document).on('cred_form_ready', function(){ //Toolset form is loaded
  jQuery('div.generelle-forhold input').on('change', function(event) {
      	var numberOfCheckedRadio = jQuery('div.generelle-forhold input[type="radio"][value="3"]:checked').length
    	jQuery('span.generelle-forhold-ikke-kontrollert').html(numberOfCheckedRadio);
  });
  var numberOfCheckedRadio = jQuery('div.generelle-forhold input[type="radio"][value="3"]:checked').length
  jQuery('span.generelle-forhold-ikke-kontrollert').html(numberOfCheckedRadio);
});

Test it in front-end, it works fine
hidden link

It is only a demo for your reference, you will need to customize those JS codes according to your website settings.

There are some related post in other website, for example:
https://stackoverflow.com/questions/6913848/count-of-selected-radio-buttons-in-jquery

#1314209

Hi,
Thank you very much for presenting an approach. You suggested solution is unfortunately not what I had in mind. Your solution is showing the total numbers in the post form. I need to get the total from already posted posts. Also I would like to show this in row above the post form.

hidden link

Hope there is a solution to this, it would conclude the testing, and bring me to production.

#1315211

I assume we are talking about this post view "Kontrollpunkt":
hidden link
It does work. I can see it outputting number in result, see your screenshot:
hidden link
What value should it output?

And I have done below modifications in your website:
Edit above post view, move the codes from section "Output Editor":

<div id="">[wpv-items-count]</div><a href="<em><u>hidden link</u></em>"> Ikke kontrollert</a>

To section "Loop Editor", within shortcode [wpv-items-found] ... [/wpv-items-found], this shortcode will be able to output result when there is any post found. See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-found

#1315267

Hi Luo,
Thank you for not giving up on me!

I am afraid this still is pending. I have now posted a new post "El 6". The first 5 radio buttons are checked by default to the value 3 (ikke kontrollert) (All the other posts are deleted)

hidden link

The total number (5) of these radiobutton should then show in this field hidden link

#1315285

Thanks for the details, there is an misunderstanding, since there is only one "el_anlegg" post satisfy all the conditions in your website, so it does output number 1 in front-end. see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-items-count

Outputs the number of posts ... 

In your case, it needs custom shortcode, but according to our support policy, we don't provide custom codes support.
I have searched it in google, and found some related posts, for example:
https://wordpress.stackexchange.com/questions/97096/how-to-query-wp-postmeta-table-for-any-specific-meta-value?rq=1
https://wordpress.stackexchange.com/questions/264924/select-multiple-wp-postmeta-keys-with-single-select

For your reference.

You can also check it with our "Toolset Contractors"
https://toolset.com/contractors/