How do I query only upcoming events and to look in them? eventOn does not give a function for that.
My code is:
$events = new WP_Query(array(
'post_type' => 'ajde_events',
'meta_query' => array(
array(
'key' => 'evcal_srow',
'value' => time(),
'compare' => '>',
'type' => 'numeric',
)
),
));
You're using start date to compare. It's incorrect way to get up coming events.
Change 'key' => 'evcal_srow' to 'key' => 'evcal_erow' will give correct results of upcoming events.
Related
I'm looking to query ACF subfields from a group within a group.
Here's my (stripped) code to show where I'm trying to target:
acf_add_local_field_group(array(
'key' => 'events_infos',
'fields' => array(
'key' => 'general_infos',
'type' => 'group',
'sub_fields' => array(
array(
'key' => 'dates',
'sub_fields' => array(
array(
'key' => 'start', // This is my sort key
...
)
)
)
)
));
I want to query the upcoming events chronologically so I would need to access; how would I format my key in the following meta_query?
get_posts(array(
'meta_query' => array(
array(
'key' => **events_infos[general_infos][dates][start]**,
'order' => 'ASC'
)
)
)
As indicated by #Stender in his comment, the answer can be found in the documentation under the heading 4. Sub custom field values".
I would like to know how to compare a date coming as custom field with the current date in a custom loop. I have following script, but it does not work...
enter$args = array(
'post_type' => 'books',
'meta_key'=>'course_date',//the format comes like this Ydm
'meta_value'=> date('d.m.Y'),
'meta_compare'=> '<'
);
My goal is to show all books with when the date is > then the current date. If the current date is > then the related post must be hidden.
Use this Query to get past event list ( 'compare' => '<') and get future events ( 'compare' => '>=')
$event_args = array(
'post_type' => 'books',
'meta_query' => array(
array(
'key' => 'course_date',
'value' => date('Ymd'),
'type' => 'DATE',
'compare' => '<'
)
),
'paged' =>$page,
'meta_key' => 'course_date',
'orderby' => 'meta_value',
'order' => 'ASC',
);
The code below should hopefully make it clear what I'm trying to achieve. The key issue is with the second array in the meta_query. I am trying to find posts where the field 'alias' has not had a post_object set.
When running the query with var_dump( get_field('alias') ); the results returned are 'NULL'. I can't figure out how to query based on a NULL post object field. Pointers would be really appreciated.
$args = array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'game',
'value' => 'baseball',
'compare' => '='
),
array(
'key' => 'alias',
'value' => NULL,
'compare' => '='
)
)
);
You're comparing it wrong. You can't check for null in meta_query. Try this:
array(
'key' => 'alias',
'compare' => 'NOT EXISTS'
)
This is basically the SQL way of saying is null.
I am really facing so much problem in fetching result of multiple values and single meta key.
Example:
I have 10 Post of 'EGG' word.
I have 5 Post of 'Butter' word.
Now i am using below query to fetch result. It suppose to show 15 post in result but its not showing total result.
$args = array(
'numberposts' => -1,
'post_type' => 'recipes',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'ingredients_repeat_%_name',
'compare' => 'LIKE',
'value' => 'Butter',
),
array(
'key' => 'ingredients_repeat_%_name',
'compare' => 'LIKE',
'value' => 'Egg',
),
)
);
Instead of using the numberposts try posts_per_page instead. You can learn more about WP_Query
I am using wordpress' meta_query to try to build a basic events system.
Each event has a number of meta keys/values. For example:
Start Date
End Date
Ongoing (Yes/No)
I want to separate events that are Ongoing (Ongoing = Yes) and Not Ongoing (Ongoing = No).
Then within my Ongoing events, I want to separate events that are:
Starting within two weeks OR Ending within two weeks
Already started AND ending beyond two weeks
My problem lies within case 1 which is, in essence:
(Start Date <= Two Weeks OR End Date <= Two Weeks) AND Ongoing == YES
Using WP_Query, I have the following:
$ongoingSoon = array(
'category_name' => 'event',
'meta_key' => 'End Date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'Start Date',
'value' => $today,
'compare' => '>='
),
array(
'key' => 'End Date',
'value' => $nexttwoweeks,
'compare' => '<='
),
array(
'key' => 'Ongoing',
'value' => 'Yes'
)
)
);
Which only returns Ongoing events that Start AND ALSO End within the next two weeks. If I change the relation to OR, then it shows events that are not ongoing as well. Is there a way to achieve what I need?
As meta_query is currently written, I'm 99% sure it's impossible to do this.
What you can do to get around that is to create a (probably private) custom taxonomy for Ongoing that acts like a boolean and only ever uses one term ('yes' or '1' or whatever). Your WP_Query would then be changed to look like this:
$ongoingSoon = array(
'category_name' => 'event',
'meta_key' => 'End Date',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'Start Date',
'value' => $today,
'compare' => '>='
),
array(
'key' => 'End Date',
'value' => $nexttwoweeks,
'compare' => '<='
)
),
'tax_query' => array(
array(
'taxonomy' => 'ongoing',
'field' => 'slug',
'terms' => 'yes'
)
)
);