Querying Pending/ Draft Events

Home Forums Calendar Products Events Calendar PRO Querying Pending/ Draft Events

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #953586
    colin
    Participant

    When events are created via community events they are created with a draft status however when i query an event by it’s post id it will not appear in the query even if i set the status. do you have a solution for this. on event_tribe function which returns event data for a give post id regardless of status

    $event_id = 1001;
    $args = array(
    ‘p’ => $event_id,
    ‘numberposts’ => -1,
    ‘post_type’ => ‘tribe_events’,
    ‘post_status’ => array(‘draft’,)
    );
    $query = new WP_Query();
    $posts = $query->query( $args );

    #953664
    George
    Participant

    Hey Colin,

    Thanks for reaching out here. First, if you already have the Event ID, then does the simpler function get_post() work for you? Like this:

    
    $post = get_post( 1001 );
    

    That example assumes that 1001 is your post ID. You can learn more about the get_post() function here → https://codex.wordpress.org/Function_Reference/get_post

    If you’re only querying for one event post, I really recommend just using get_post() instead of WP_Query.

    If you want to use WP_Query instead, then one thing I noticed about the code you posted here was a typo for the ‘post_status’ parameter. In the code you posted, it looked like this:

    
    ‘post_status’ => array(‘draft’,)
    

    That extra comma after the word ‘draft’ could be causing problems, so make sure it’s just this:

    
    'post_status' => array( 'draft' )
    

    Let us know if any of this information helps!

    Cheers,
    George

    #953674
    colin
    Participant

    get_post($event_id) does the trick thanks

    #954371
    George
    Participant

    Nice! Best of luck with your project Colin, cheers.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Querying Pending/ Draft Events’ is closed to new replies.