V
V
VitStar2018-06-16 11:07:48
WordPress
VitStar, 2018-06-16 11:07:48

Make a selection of posts of this kind?

Good day.
I'm scratching my head over this one.
The site has monthly reports. Implemented through custom posts.
There are rubles with years and posts where inside there is an arbitrary field for choosing which month it is.
Everything seems to be working normally.
But the site also has charts that want to filter for a certain period.
That is, ( prntscr.com/jvld72) there is a default chart that displays the data of this particular month. But you can filter let's say for 3 months. And the data of the current month + 2 before it should be taken.
Question:
How can you get 2 of these months? It is not necessary that the posts were published 1 after the other. So they can be mixed. And for the selection criteria, I think you need to somehow take an arbitrary field (format month: 06) and taxonomy (year)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-06-16
@Yan-s

What about posts that don't have a publication date?
We take the current month and subtract two from it - the range for querying the database by the publication date. Add sorting by the same date and you're done.

I
Ivan Kozlov, 2018-06-16
@trampick

You need to use meta_query along with tax_query in your request . If you need to use a query for 2 years (this will happen when you select January 2018 and November-December 2017), then you will have to split it into 2 queries.
Good thing it needs to be redone. Add a date field to the post in Unix Timestamp format. Then requests will be easier, and everything will work faster.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question