Skip Navigation

[Resolved] List results of content type order by field year

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/Karachi (GMT+05:00)

This topic contains 14 replies, has 2 voices.

Last updated by Waqar 1 year, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2646497
pic2.JPG
pic1.JPG

Hi, I'm Jose and I have a problem using Toolset, let me explain...

We have one content type: MIS DATOS (translate MY DATA), where we can add users as subscriptors.
Those users, can add new entries in another customs types: BOOKS, ARTICLES, etc... and we display all those results of all the subscriptors in pages, like:

hidden link

you can check the first option: ARTÍCULOS DE REVISTA JCR is the one that I'm testing.

Ok, by now.

The thing is that those BOOKS, ARTICLES, etc... have a field called AÑO (translate YEAR), and when we display all,
we must order the results by this field YEAR.

The view that display those results is in pic2.jpg
but you can check in this url that the entries are not order by YEAR:
hidden link

each article could be from differents susbcriptors, we need a list of all but order by the field YEAR of each CONTENT TYPE.

Thanks.

#2646961

Hi,

Thank you for contacting us and I'd be happy to assist.

In your screenshot, the view is set to order the results by 'Post date', which is the published date of the posts.
( screenshot: hidden link )

To filter the results by that 'AÑO' field, please select it in that 'Order by' setting and the view will order the results based on that.

regards,
Waqar

#2647219
Captura.JPG

Hi Waqar,
thanks for your reply.
Yes, I do this but still not working. You can see it in the image captura.jp

The thing is that this view display:

Articles from one subscriber and then below more articles from another subscriber but not order by year.

Thanks.

#2647229

Let me explain one thing:

In ARTÍCULOS DE REVISTA JCR
The first three articles are from one subscriber, the others three are from another subscriber.
Thanks.

#2647533

Thank you for sharing this update.

Please check your website's active plugins list and see if there is a plugin that can change the order settings for the posts. Such third-party plugins can change the order of the results coming from the views.

In case the issue still persists, you're welcome to share temporary admin login details, for further troubleshooting.

Note: Your next reply will be private and making a complete backup copy is recommended before sharing the access details.

#2648017

Thank you for sharing the access details.

The ordering by the 'ano' field through the view's order settings isn't possible because this list is getting generated by two nested views and the source of the parent view results in not just a single post but multiple.

This needed a workaround and custom code and here are the steps, that I took:

1. To keep the HTML structure of this list minimal, I removed the ul and li tags from both these views ( i.e. 'GICOT Investigadores JCR' & 'GICOT JCR' ).

Also checked the option 'Disable the wrapping DIV around the View' in both of these views.

2. Wrapped the actual output of the list items from the child view 'GICOT JCR', in a special div container with class 'sortable-item' and year field's value, in the 'data-index' attribute:
( screenshot: hidden link )


<div data-index="[types field='ano'][/types]" class="sortable-item">
........
</div>

3. Wrapped the shortcode of the parent view inside a div container with class 'sortable':
( screenshot: hidden link )


<div class="sortable">
[wpv-view name="GICOT Investigadores JCR" wpvgrupoinvestigacion="gicot"]
</div>

The goal was to achieve this HTML structure for the list items so that a custom script can be used to order them based on the year value coming from the 'ano' field in the 'data-index' attribute:


<div class="sortable">
    <div class="sortable-item" data-index="year-value">...</div>
     <div class="sortable-item" data-index="year-value">...</div>
     <div class="sortable-item" data-index="year-value">...</div>
     <div class="sortable-item" data-index="year-value">...</div>
</div>

4. The last step was to include some custom script in the parent view, to make this ordering work:
( screenshot: hidden link )


jQuery(document).ready(function( $ ) {
$('.sortable').each(function(){
    var $this = $(this);
    $this.append($this.find('.sortable-item').get().sort(function(a, b) {
        return $(b).data('index') - $(a).data('index');
    }));
});
});

Note: The custom code examples from our forum are shared to get you started in the right direction. You're welcome to adjust them as needed and for more personalized customization assistance, you can consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

#2648147

Hi Waqar,
ok thanks a lot. I'm gonna try in all views and I'll reply you.
Thanks.

#2648149

Sure, please take your time and let me know if you have any follow-up questions.

#2648229

Hi Waqar,
I have done all your steps and everything seems fine.
But just one thing, in some views I lost the message that display when no results:

[wpv-no-items-found]
[wpml-string context="wpv-views"]No se han encontrado datos.[/wpml-string]
[/wpv-no-items-found]

You can see here:
hidden link

in LIBROS (BOOKS) don't display this message, but in other views it does, and all the views are the same.

Thanks.

#2648231

Same here in all the investigation areas:
hidden link

Here there are no results but we need that the message of "Nothing found" displays.
Thanks.

#2648305

The challenge is that if the 'no items found' text is included in all views, there can be cases where this message is shown multiple times.

For example, check the tab 'Tesis doctorales' on the 'Grupo GICOT' page.

Here is a trick you can use:

1. Make sure that all your parent and nested views are showing the 'no items found' message. But also add a class 'no-items-found-text' to its 'strong' HTML tag:


[wpv-no-items-found]
<strong class='no-items-found-text'>[wpml-string context="wpv-views"]No se han encontrado datos.[/wpml-string]</strong>
[/wpv-no-items-found]

2. Next, in any one of your views, include this custom CSS code, that will show only the first instance of this 'no items found' message, within each tab, hiding any duplicates:


.elementor-tab-content strong.no-items-found-text {
    display: none;
}

.elementor-tab-content strong.no-items-found-text:first-of-type {
    display: block;
}

#2648621
3.JPG
2.JPG
1.JPG

Hi Waqar,
I just do what you told me, but I have another problem, now in every list displays:
The nothing found message and the results 🙁

I send you pics from the parent and nested views.

Thank you so much for your help.

#2649205

I've updated the custom script slightly so that it also removed the 'no items found' message if any single result is found, in the individual tab:


jQuery(document).ready(function( $ ) {
	$('.sortable').each(function(){
		var $this = $(this);
		$this.append($this.find('.sortable-item').get().sort(function(a, b) {
			return $(b).data('index') - $(a).data('index');
		}));

		if( $this.find('.sortable-item').length )         // use this if you are using id to check
		{
			$this.find('.no-items-found-text').remove();
		}
	});
});

#2649565

Hi Waqar,
ok, thanks. I'll test it and I'll tell you.
Thanks!

#2649597

Glad I could help and let me know if you have any follow-up questions.

And for a new question or concern, you're welcome to start a new ticket.