A
A
alex_mirg2019-02-19 20:17:40
CMS
alex_mirg, 2019-02-19 20:17:40

How to link posts to the days of the month in wordpress and display them depending on the selected day?

Please direct how to implement such a task:
It is necessary to display a proper nutrition menu for every day on the main page using Ajax .
ON THE SITE:
The user enters the page, selects the desired day, the menu is loaded where he selects (male / female)
The desired menu is displayed on the screen.
FROM THE ADMIN: The
admin enters the admin panel: distributes for 1-2 weeks in advance on which day which menu should be displayed.
In my opinion, it would be very cool to mark all this in some kind of calendar
SCREENSHOT:
5c6c39a9cbf44346873903.jpeg
MY PLAN:
1. I create an arbitrary post type (the post contains both a menu for a man and a woman.)
2. The site is on bootstrap, so using bootstrap tabs, the post is divided into two parts (male/female)
3. A calendar is created in which it is set to which days which records to attach.
Customize output with ajax.
QUESTIONS:
1. Have I made a correct action plan?
If not, what is the best way to accomplish this task?
2. How to create a distribution of records by day? And how to set the output exactly by day?

So far I have no idea where to dig.
Ps I already know how to create custom post types, taxonomies. Use custom fields to fill in these records. I also learned how to display posts using ajax.
But I haven’t come across sorting and outputting according to the calendar yet

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Vorotnev, 2019-02-19
@alex_mirg

1. We store the day in postmeta (custom field) or in taxonomy (after all, the days will be repeated, 1...31, right?)
2. Display with a get_posts() or WP_Query query, compose the parameters in the desired form ( meta_query if custom field, tax_query if taxonomy)
3. Profit.
To be blunt, in your ajax callback (php function) add:

$args = [
    'posts_per_page' => 1, // запись ведь у нас одна будет
    'no_found_rows' => true, // не нужно SQL_CALC_FOUND_ROWS, запрос будет сильно быстрее выполняться
    'post_type' => 'custom_post_type_name', // название кастомного типа записи
    'post_status' => 'publish', // только опубликованные
    // тут пишем meta или tax подзапрос (см. ссылки на документацию выше)
];
$query = new WP_Query( $args );
// Наш пост будет в массиве $query->posts
$post = reset( $query->posts );
// Ну или делайте обычный WordPress Loop - тут уж как удобнее.

But in general, I would keep the menu for women and men separately, as separate posts. Day is a full date in the metadata. And he took the data with Ajax through the callback, but with the help of the REST API. Then it is enough to pass the meta-field (name and desired value) to the apish filter. All this is in the REST API documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question