Converting working Logic to Meta query
-
We are using Post as the event listing and has included two custom taxonomies of ‘event start date’ and ‘event end date’. The custom taxonomies are being saved in database as unix timestamps.
On the archives, we are showing Events that are either currently running, or scheduled in future or has end date of today.
As implied, we used a logic to compare ‘start date’ and ‘end date’ from ‘today date’ (current date).
The logic is –
if ( have_posts() ) : while ( have_posts() ) : the_post(); if( ($event_end >= $todaydate && $todaydate >= $event_start) || ($todaydate < $event_start && $todaydate < $event_end) ) { echo '<div id="content">'; // stuff echo '</div>'; } endwhile; else : endif;
The problem is, we are using this logic in the loop to show posts, so actually database query loads all the posts and then we filter the events to be shown and display them.
This seems wrong because query has to do all the work to load 100 posts (for example) whereas only 50 posts are eligible to be shown (because other 50 are the events that were scheduled in past).
So, can you suggest any way with which we can implement our working logic in wordpress query (meta query) so that only the eligible posts get fetched instead of all posts.
- The topic ‘Converting working Logic to Meta query’ is closed to new replies.