Skip Navigation

[Resolved] Month archive WP for all custom types with layout

This support ticket is created 6 years, 2 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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by yulyaB 6 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1142934

I want to do archive month, but now in this page only posts. I try to add other post types, for example, events, ads, other.
How to filered by date custom post types in archive page? I see that i can filtered by URL parametr, but i'm not shure how to do theese.

#1143021

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Screenshot-2.png
Screenshot-1.png

Hi Yulya

By default the WordPress monthly archives only include the standard WordPress posts.

You can create a custom archive design for the monthly archives by going to Toolset > WordPress Archives and adding a new custom archive and assigning it to the monthly archive (see screenshot-1).

You can then specify what content should be included. Note the edit button where it says "This archive will include Posts only". When you press that you can choose which post types should be included in the archive (and you can remove Posts if you want).

The month archives work according to the URL, so the archive for this month would appear at site.com/2018/11 for example.

Adding filter controls by standard fields (such as post_date) is currently not supported. We do have a request for that, and you can add your vote here: https://toolset.com/feature-request/?wpv_post_search=filter+for+post+date&wpv-wpcf-plugins=Views&wpv_view_count=686737

Could I also ask you an unrelated question?

We have just begun trialling offering chat support. When you created this thread you should have seen the option to chat immediately with support or to submit the thread as normal, and it seems like you chose to submit as normal.

Do you have any comments?

#1143042

In these case, i see that all post types are displayed in one list. But i want, that it was custom list for other types. For example, event with date and picture or slider, post - list of posts of month, and other custom settings and desing.

Yes, i see chat. i need some time for translate english, I can’t chat quickly in English.

#1143077

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, I don't understand what you are trying to do, could you please give some examples to explain?

#1143087
Screenshot_1.png

Please, see picture

#1143168

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Yulya

Archives don't work like that, the posts of different types are returned in the order you set (e.g. most recent first or alphabetical), and are not grouped together by post type.

For something like your screenshot you would need to have the archive just show standard posts, for example, and add additional Views to display each of the other kind of posts, one for each post type. You would be best using Layouts to create the custom archive so that you can lay the main archive and the additional Views out on the page how you require.

The main problem is how to pass the month in question to the Views so they show only the posts for the month set by the URL.

That will probably need a little bit of extra code.

I'm finished for the day, I'll take a look at that in the morning.

#1143734

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Yulya

So I set up a test site locally and worked up some code that you can use to enable this.

To recap, you will need to create a custom WordPress archive for the monthly archives. You can leave this to just display matching standard posts, as per the default.

You then need to make Views for each other post type you want to also display on this page.

Each View should include a post date Query Filter which, by default, will filter according to the current year and the current month. Our custom code will override these to use the actual year and month from the monthly archive. Make a note of the View IDs, you will need these.

Now, you can either add these Views into the output section of the custom archive (outside of the wpv-loop tags), but I recommend you use Layouts. Create a Layout which you assign to the monthly archives, then insert the actual archive itself using a WordPress Archive cell, and also add each of the Views you separately created in their own cells.

Now go to Toolset > Settings > Custom Code and add the following code snippet:

/**
 * Set View date filter arguments from current month archive
 */
function tssupp_filter_query($view_args, $view_settings, $view_id) {

	if (in_array($view_id, array( 123, 456 ))) {

		global $wp_query; // the query for the archive, not the View

		if (isset($wp_query->query_vars['year']) && isset($wp_query->query_vars['monthnum'])) {

			$view_args['date_query'][0]['year'] = $wp_query->query_vars['year'];
			$view_args['date_query'][0]['month'] = $wp_query->query_vars['monthnum'];
		}
	}
	return $view_args;
}
add_filter('wpv_filter_query', 'tssupp_filter_query', 101, 3);

You need to edit the View IDs (123 and 456 in my example; you can add as many as you need).

Then when you visit a URL such as site.com/2018/10/ you will see the monthly archive, and each of your post types will be listed separately.

#1143854

I try it. It works! Thanks!

But some bugs: If there are no posts in this month, the month archive page does not exist.

#1143868

My issue is resolved now. Thank you!