pass start date in pre get posts

Home Forums Calendar Products Events Calendar PRO pass start date in pre get posts

  • This topic has 0 replies, 2 voices, and was last updated 6 years ago by bartmarkten.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1491433
    bartmarkten
    Participant

    Hello,

    We are showing events on category page , where we directly use this code
    if (have_posts()) :
    while (have_posts()) : the_post();

    to show events.

    Also , we want to show only upcoming events , so we want to filter data using “pre_get_posts” and we are passing folowing in pre get posts

    $start_date_query = array(
    array(
    ‘key’ => ‘_EventStartDate’,
    ‘value’ => date(‘yyyy-mm-dd hh:mm’),
    ‘compare’ => ‘>=’
    )
    );
    $query->set( ‘meta_query’, $start_date_query );
    $query->set( ‘orderby’, ‘event_date post_date’ );
    $query->set( ‘order’, ‘ASC’ );
    $query->set(‘eventDisplay’, ‘upcoming’);

    But this shows all past and future events , means start date meta query is not working , can you please tell us how can we use pre get post parameters to make this work.

    Also , We are not able to use directly “tribe_get_events” function , so please let us know solution for above , Thanks.

    Also , we want to show all recursive events for some category and not all recursive events for other categories , you have suggested to use “tribeHideRecurrence” query parameter in pre get posts , Can you also let us know how can we use this parameter with default WordPress pre get post function with above shown parameters.

    #1493192
    Victor
    Keymaster

    Hi Bart!

    Thanks for getting in touch with us!

    First, please let me note that we are fairly limited in how much support we can give for custom development questions like that. That said, we always like helping out and at least point users into the right direction as much possible.

    I’m not exactly sure where and how you are using the code you mention. By default, the events category pages show upcoming events and you can use the Recurring event instances and the Front-end recurring event instances toggle options in the events general settings to hide/show recurring event instances.

    Could you please share with us the complete code you are using and where you are placing it? I’d be happy to have a look and try it on my end so I can see where the problem is.

    Let me know.

    Best,
    Victor

    #1494043
    bartmarkten
    Participant

    Hello ,

    Sorry for i can not explain myself clearly.

    Like is it simply possible to use WP-Query to get future events instead of “tribe_get_events” function ?

    I need it because i want customize the functionality.

    Thanks.

    #1494312
    Victor
    Keymaster

    Hi Bart!

    Yes, that’s absolutely possible. The tribe_get_events() function > https://theeventscalendar.com/knowledgebase/using-tribe_get_events/ uses the WP_Query > https://codex.wordpress.org/Class_Reference/WP_Query to fetch the events, so you should be able to use it in order to fetch events.

    I hope that helps. Let me know if any follow up questions.

    Best,
    Victor

    #1494977
    bartmarkten
    Participant

    Hello ,

    I tried following different codes for using WP query instead of tribe_get_events , but nothing worked:

    I want to pass parameters into pre_get_posts hook for this , so tried following :

    1) $query->set( ‘start_date’, date( ‘Y-m-d H:i:s’ ) );
    2) $start_date_query =
    array(
    ‘key’ => ‘_EventStartDate’,
    ‘value’ => date(‘yyyy-mm-dd hh:mm’),
    ‘compare’ => ‘>=’,
    );
    $query->set( ‘meta_query’, $start_date_query );

    3) $start_date_query = array(
    array(
    ‘key’ => ‘_EventStartDate’,
    ‘value’ => date(‘yyyy-mm-dd hh:mm’),
    ‘compare’ => ‘>=’,
    )
    );

    $query->set( ‘meta_query’, $start_date_query );

    Can you help me for this please ?

    #1495124
    Victor
    Keymaster

    Hi Bart!

    I’m sorry to hear that’s not working for you.

    Again, I don’t really know what you are trying to accomplish and what you mean by the code not working. Is it giving any error? Are you placing it in your theme’s functions.php file?

    If you are trying to modify the main events query, you can find the main query at wp-content/plugins/the-events-calendar/src/Tribe/Query.php

    If you let me know exactly where you are adding that code and what you are trying to accomplish with it, I’d be happy to point you in the right direction as much possible.

    You can even send us a copy of the code you are using in a text file so we can run some tests with it. Do note that you won’t be able to attach .txt files to your response, so I’d recommend compressing it in a zip file.

    Let me know about it.

    Best,
    Victor

    #1515977
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘pass start date in pre get posts’ is closed to new replies.