Skip Navigation

[Resuelto] count the items in an RFG inside an RFG and use it in condition

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:
The user would like to display a different icon based on the count of nested RFG items in a nested view.

Solution:
Toolset does not offer built-in feature to count the number of items in an RFG. It will require custom code.

However, based on how the user has set up the nested view, we can implement a solution using Javascript. Check this reply https://toolset.com/forums/topic/count-the-items-in-an-rfg-inside-an-rfg-and-use-it-in-condition/#post-2041359

This support ticket is created hace 3 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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: Africa/Casablanca (GMT+01:00)

Este tema contiene 2 respuestas, tiene 2 mensajes.

Última actualización por jorgel-4 hace 3 años, 6 meses.

Asistido por: Jamal.

Autor
Mensajes
#2040843

I need to count the number of items in an RFG inside an RFG and use the count inside a condition

#2040887
#2041359

I could not make the custom code return the count of the images in each unit, either using the view, or using the relationship API(toolset_get_related_posts). However, I was able to come up with a Javascript-based solution that is optimal.

Instead of counting the number of images using a shortcode or a function in the server, which will trigger more database queries and increase the page load, I added a special class(no-unit-image) to the wpv-no-items-found section of the view:

	[wpv-no-items-found]
		[wpml-string context="wpv-views"]<small class="no-unit-images"></small>[/wpml-string]
	[/wpv-no-items-found]

Then using a Javascript, I search for this class, which means the unit does not have any images, and then, I apply the greyscale style for the image button.

jQuery(function($){
    $('.no-unit-images').each(function(){
        var $this = jQuery(this)
        var container = $this.closest('.ml-0');
        var image = container.find('.btn-unit-img>img');
        image.attr('style', 'webkit-filter: grayscale(100%); filter: grayscale(100%);')
    })
})

Please check if that's what you are looking for enlace oculto

#2041397

Awesome!! Thank a lot Jamal, it's working perfectly now!! 😀