Wednesday, July 6, 2022
HomeWordPress Developmentposts - Return data between two meta datetimes saved as strings

posts – Return data between two meta datetimes saved as strings


I’ve a begin date and an finish date saved as submit meta fields (so strings). I need to return posts between two date ranges. I assumed it could be a easy string comparability – one datetime represented as a string ought to nonetheless be capable of be in contrast (<= and >=) with one other datetime saved as a string. However MySQL is returning surprising outcomes. For instance, of the 13 legitimate data it ought to return for a specific search, it returns a (seemingly) random subsection, typically 3 data, typically 6 data, typically 8 data, typically a unique 6 data, and so forth, for queries solely seconds aside.

That is the question I am utilizing:

            $meta_args = array(
                'relation' => 'AND',
                array(
                    'key'     => 'package_startdate )',
                    'worth'   => "$now_date",
                    'evaluate' => '<',
                ),
                array(
                    'key'     => 'package_enddate',
                    'worth'   => "$now_date",
                    'evaluate' => '>',
                ),
            );
            $args = array(
                'post_type'         => 'saleitems',
                'posts_per_page'    => 50,
                'meta_query'        => $meta_args,
                'meta_key'          => 'display_order',
                'orderby'           => 'meta_value_num',
                'order'             => 'ASC'
            );
            $question = get_posts( $args );

A typical submit meta for package_startdate or package_enddate may be 2022-04-29T10:30.

WordPress does not seem to permit a easy technique to utilise STR_TO_DATE or related in these queries and I am unable to work out why it isn’t returning the right outcomes.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments