First, the sample WHERE
clause you provide doesn’t make sense. That is not how to write a query that will return “between a range of startDate and endDate”. Secondly…
I am basically looking for posts which are between a range of
startDate and endDate and should show further posts also.
It is not clear what you mean by “show further posts also” but the only thing that makes sense to me is that you want to show posts outside your range– presumably posts greater than startDate
as in the first clause of your confusing sample WHERE
. That being the case, all you need is:
$args = array(
'posts_per_page' => 100,
'post_type' => 'create_events',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'startDate',
'value' => date('Y-m-d'),
'compare' => '>'
),
),
'orderby' => 'meta_value',
'meta_key' => 'startDate',
'order' => 'DESC'
)
);
You are correct that the arguments you were trying to use won’t work. WP_Query
is not capable of logic that complicated, but, as I’ve said, your sample WHERE
doesn’t make sense. Draw it on a number line and you should see what I mean. (startDate <= '2013-12-10' and endDate >= '2013-12-10')
gives you almost the opposite of what your English description asks for.
Also…
It should be noted that using this to replace the main query on a page
can increase page loading times, in worst case scenarios more than
doubling the amount of work needed or more. While easy to use, the
function is also prone to confusion and problems later on. See the
note further below on caveats for details.http://codex.wordpress.org/Function_Reference/query_posts (emphasis mine)