Skip Navigation

[Resolved] Archive list by "date" custom field

This support ticket is created 8 years 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 7 replies, has 2 voices.

Last updated by Beda 7 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#387263

I have a CPT with custom filed "date-of-event"

I want to add archive list by month/year for posts in that CPT

For example, the archive list will be the following:

March 2016
December 2015
September 2015

Each item in this archive list will link to a archive page that list all post where the "date-of-event" field falls within that month/year.

So a post that has the custom field "date-of-event" of 12/13/2015 will show in the list for December 2015

The idea is very similar to the WordPress blog archive, but the only difference is that the query will be by a custom field, not the post date.

#388644

This can not be achieved with Toolset WordPress Archives.

Those are just wrappers to design the native WordPress archives.
No queries or parametric searches or filters can be used there, as in native Toolset Views.

So you need to create Post Views to achieve this.

In those, you can query Filter and Sort by this Custom Field.

Then you can insert the Views anywhere you want on your Websites and link the Posts or Date Fields to other Views, filtered by this Field.

You may also construct the View to display posts by Date Field passed in the URL argument, so whenever you pass the Date via URL (this means, you click on a link somewhere and pass the Date in the URL, the same view can be used to display different Results.

It is documented here:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/
https://toolset.com/documentation/user-guides/views/
https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/
https://toolset.com/documentation/user-guides/filtering-views-query-by-date/

Please let me know if you need further infos about this.

Thank you for your patience.

#389167

Thanks for the links Beda, I was able to create the veiw by date and format the results. As of now, my links looks like this:

04/2013
10/2011
10/2011
04/2011
01/2010

Each list items link the a specific post with that date.

What I want to do is have them go to a page that lists all post that match that same month/year.

As you can see above, "10/2011" is listed twice and links to it''s own specific post. I want it to be listed once and to be linked to a page that lists all the posts where the custom field value matches the month/year.

Thanks

#389417

Yes, this is expected.
A View will query your Post Type, and order it by your Custom Field

But you will need a Custom Code Query adjustment to strip all "identical" Field Contents and output only the one that are "unique", in your Post View.

Linking to a Page where you see all the Posts with the "clicked" Date (Custom field value) is done by creating a View, that lists posts where the Custom Field's value is a value you pass with the URL argument.
I liked to it previously:
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

So that means, on the first view you output the Dates (Custom Fields)
You wrap them in a Link.

<a href="your-site.com/page-with-second-view/?your-url-argument=[types field="your-custom-field"][/types]">[types field="your-custom-field"][/types]"</a>

Now, when you click on above Link, you are directed to a page, where you inserted the View that lists posts where the Custom Field's value is a value you pass with the URL argument.
The URL Argument will determine what posts are displayed on that page.

Thank you

#395991

Three Questions:

1. Do you mean that I will need to create a new view for "Archive Year".

2. How do I a Custom Code Query adjustment to strip all "identical" (mm/yy) Field Contents and output only the one that are "unique"(mm/yy), in your Post View.

3. My custom filed value has the full date. How can I specify only month/lyear from that field to filter by?

#396056

You need to create a new View that does show the posts where the Date Field is matching the URL parameter (which you will pass from the First View)

1. The View where you create your Links to click on.
The Loop holds code like this:

<a href="your-site.com/page-with-second-view/?your-url-argument=[types field="your-custom-field"][/types]">[types field="your-custom-field"][/types]"</a>

2. The second View is insert on a different page (page-with-second-view) and will have a Query Filter

Select items with field: dates is a number equal to URL_PARAM(date)	

3. To customize the View Query Output you could use the Views Filters along with Custom PHP:
https://toolset.com/documentation/user-guides/views-filters/
https://toolset.com/documentation/user-guides/views-filters/wpv-before-display-post/

4. You can not set up a Date Field with Types that holds ONLY a month and year.
Types Date Fields hold either a exact date or a exact date with an exact time.

Thank you

#399379

I updated the link:

<a href="/verdicts-archive/?date=[types field="date-of-verdict" format="m/Y"][/types]">[types field="date-of-verdict" format="m/Y"][/types]</a>

the url now looks like this: .../verdicts-archive/?date=04/2013

and added the new view page:
Query Filter: Date Of Verdict is a DATE equal to URL_PARAM(date)

But all the links return no results

I'm not sure which of these to use in order to display the posts that match by month and year:

https://toolset.com/documentation/user-guides/views-filters/
https://toolset.com/documentation/user-guides/views-filters/wpv-before-display-post/

I just need something that works like the default WordPress blog archive

Also, The first view of links is still not correct. How do I narrow down the list to month/year without having duplicates?

#399458

1. About changing the Views' Loop output see my reply above #3:
https://toolset.com/forums/topic/archive-list-by-date-custom-field/#post-396056
and:
https://toolset.com/forums/topic/archive-list-by-date-custom-field/#post-389417

It needs Custom Code.

2. Your links return no results because that is not a date.
It's a Year and Month.

To adjust your View to return Posts by a Date set in a Types Custom Field you need to carefully follow this DOC:
https://toolset.com/documentation/user-guides/date-filters/

As you will see, we store our Date as a NUMBER (timestamp) not as a DATE.

Related to your goal:
"I want to add archive list by month/year for posts in that CPT"

You can mimic the Archive by creating your View, which returns posts with the Custom Fields Date value as example:

Select items with field: dates is a number greater than or equal URL_PARAM(begin)	

(Would display posts that are after a certain date)

Keep in mind you need to use NUMBERS (timestamp) as this is the value in a Custom Field Date.

You can also use "hardcoded" values as THIS_MONTH or similar, but those will not accept URL parameters.

All possibilities to filter by Date from a Custom Field are elaborated in the above linked DOC.
It's not possible without Custom Code to to strip all "identical" (mm/yy) Field Contents and output only the one that are "unique"(mm/yy)

The Filter to use is linked above, here for reference again:
https://toolset.com/documentation/user-guides/views-filters/
https://toolset.com/documentation/user-guides/views-filters/wpv-before-display-post/
(first link is just the list of all Filters, for your reference)

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