Sunday, August 7, 2022
HomeWordPress Developmentwp question - WP_Query - Learn how to get all posts of...

wp question – WP_Query – Learn how to get all posts of particular days of week by customized subject date?


I’ve a filter on frontend with days of weeks, and I want present solely posts which can be printed on especific day (or days).

The date are on customized subject day_of_event (the filter is predicated on this subject, not of submit printed date), and all dates are on date format, like “20220806”.

When the consumer ship filter “Sunday” on frontend, one thing like:

$filter = ['sunday'];

I want filter all posts which can be printed with customized fields “day_of_event” that match with particular day “Sunday”.

Instance posts:

Publish ID  | Title                    |  Date of customized subject  |  Date printed

1        |  Occasion check             |  20220806 -> Sunday    |  20220804 -> Friday
2        |  One other occasion          |  20220808 -> Monday    |  20220801 -> Monday
3        |  Welcome occasion          |  20220816 -> Twersday  |  20220805 -> Saturday
4        |  Course occasion           |  20220808 -> Monday    |  20220807 -> Sunday
5        |  Ending occasion        |  20220724 -> Sunday    |  20220622 -> Wednesday
6        |  Learn how to make a app      |  20220717 -> Sunday    |  20220622 -> Wednesday
7        |  Learn how to make a web site  |  20220621 -> Sunday    |  20220622 -> Thursday

If the consumer ship $filter = ['sunday'] I acquired posts 1, 5, 6, 7.

If the consumer ship $filter = ['monday'] I acquired posts 2, 4.

If the consumer ship $filter = ['monday', 'twersday'] I acquired posts 2, 3, 4.

How I can do that with WP_Query? To be extra particular, I am already utilizing one other filters with meta within the archive template, and I want use filters right here:

add_action( 'pre_get_posts', perform ( $q ) {
    if(!is_admin() && $q->is_main_query()) {
        if($q->is_post_type_archive('programs')) {
            $q->set(
                // ...
            );
        }
    }
});

Thanks.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments