Skip Navigation

[Resolved] How to sort AND limit custom post type archive listing

This support ticket is created 5 years, 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

Tagged: 

This topic contains 10 replies, has 3 voices.

Last updated by Minesh 5 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#1111175

Hi,

I have a site that lists Events as a custom post type.

hidden link

I want to do two things:

1) Have the archive page list the posts in chronological order by the custom field "Event Start Date" (slug 'start-date')

AND

2) NOT show any events where the "Event End Date" has expired (slug 'end-date').

I realize this is probably not a native feature of ToolSet.
HOWEVER I have seen some other support threads where it suggests it is possible to sort the archive by a custom field.
e.g. https://toolset.com/forums/topic/sort-custom-post-archive-by-custom-field/

So at least the first part seems easily doable.

-----------------

Alternatively, would it be better to set this up as a View?
And if so, <b>how to substitute a View for the default archive listing?</b>

#1111360

Hello,

That thread you mentioned above is outdated, in the latest version of Views plugin, you can setup a wordpress archive for your archive page, and setup it to be ordered by your custom date field:
https://toolset.com/documentation/user-guides/creating-wordpress-custom-post-archives/

In the wordpress archive, you can add a custom field filter: the "Event End Date" is not expired:
https://toolset.com/documentation/user-guides/date-filters/

#1114078

Thank you.
I will test this and get back to you tomorrow.

#1114126

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo has a day off today. He will get back tomorrow and reply you here.

#1114790

OK, please update this thread if you need more assistance for it.

#1115894

The "sorting" was extremely easy.
I can see that Archives have an "ordering" setting.

Solving the second part of m question is less obvious.

Within the archive I want users to be able to do a custom search for events that fall between two dates.
i.e. Starting on/after a START DATE and ending on/before an END DATE.

BUT I also want to do a preliminary filter to remove any events from the archive list that have expired
i.e. with an END DATE earlier than NOW().

It doesn't seem possible to do that with the Archive filter.

Is there maybe a way of adding some custom code to functions.php that does a preliminary "filter out" of any expired events before putting them into the archive list?

#1116032

Are you going to add two different filters on the same date field "END DATE":
- Starting on/after a START DATE and ending on/before an END DATE
- with an END DATE earlier than NOW().

If it is, it needs custom codes, Views UI only allow one filter on the same custom field, I suggest you try with Views filter hook "wpv_filter_query" to apply your custom filters:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
When displaying a View listing posts, this filter is applied to the arguments being generated by the View settings before they are passed to the WP_Query class.

#1117135

"If it is, it needs custom codes, Views UI only allow one filter on the same custom field, I suggest you try with Views filter hook "wpv_filter_query" to apply your custom filters:"

OK. That's what I thought.
I'm more designer than coder.
Any chance you can take a stab at writing the custom function for me?

#1118097

Since it is a custom codes question, please provide a test site with the same problem, also point out the problem page URL and view URL, I need a live website to test and debug the codes.

#1120371

Do you need FTP access as well?

#1120761

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Luo is on vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.

Yes - please share all required information.

I have set the next reply to private which means only you and I have access to it.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.