A
A
Ahmad Dusmatov2020-04-23 09:13:50
WordPress
Ahmad Dusmatov, 2020-04-23 09:13:50

How to generate SQL from this wp_query?

$query = new WP_Query(array
            (
                'post_type'=>mec_books,
                'posts_per_page'=>-1,
                'post_status'=>array('publish', 'pending', 'draft', 'future', 'private'),
                'year'=>2020,
                'monthnum'=>05,
                'day'=>20,
                'meta_query'=>array
                (
                    array('key'=>'mec_event_id', 'value'=>$event_id, 'compare'=>'='),
                    array('key'=>'mec_ticket_id', 'value'=>$ticket_id, 'compare'=>'='),
                    array('key'=>'mec_verified', 'value'=>'-1', 'compare'=>'!='), // Don't include canceled bookings
                )
            ));


Такой запрос находит очень много записей, хотя в базе примерно 3к записей для этого post_type

SELECT
*
FROM
wp_posts AS p
LEFT JOIN wp_postmeta AS pm
ON
pm.meta_key = 'mec_event_id' AND pm.meta_value = 28222
WHERE
p.post_type = 'mec-books' AND p.post_status IN(
'publish',
'pending',
'draft',
'future',
'private'
)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ahmad Dusmatov, 2020-04-23
@dusmatoff

echo "Last SQL-Query: {$query->request}"; Decided so. Thanks Dmitry

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question