Can\’t Seem to Use the Right Post Type

Home Forums Calendar Products Events Calendar PRO Can\’t Seem to Use the Right Post Type

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1334246
    stevevgl
    Participant

    If I was going to take these arguments for use with a WP_Query …

    $myArgs = array(
       'post_type' => 'any'
    );

    …post type of “any” works, showing me all my post types, including regular posts and custom post types like The Events Calendar events.

    However, when I try to limit it to just The Events Calendar items, it returns nothing. I figure something is wrong with the post_type.

    I have tried tribe_events as well as Tribe__Events__Main::POSTTYPE, but I can’t figure out how to reference this post type.

    Please help. 🙂

    • This topic was modified 8 years, 8 months ago by stevevgl.
    • This topic was modified 8 years, 8 months ago by Jennifer.
    #1334330
    Jennifer
    Keymaster

    Hi Henry,

    tribe_events is indeed the correct post type, so it should work with WP_Query. Are you using any other arguments besides ‘post_type’?

    We do have a function similar to WP_Query specifically for pulling events: tribe_get_events. You can use many of the same arguments with it as you can with WP_Query.

    Let me know if that works for you!

    Thanks,

    Jennifer

    #1334521
    stevevgl
    Participant

    Hi, Jennifer! Thanks for responding!

    Although I eventually will, at this point, I don’t have any other arguments, because I just kept stripping them away to try to troubleshoot the problem. And here is what is going on:

    I will run this query:

    $MyQuery = new WP_Query( $myArgs );

    And loop through like this:

    echo '<ul>';
    	while ( $MyQuery->have_posts() ) {
    		$MyQuery->the_post();
    		echo('<pre>');
    		print_r($post);
    		echo('</pre>');
    		echo '<li>' . get_the_title() . '</li>';
    	}
    	echo '</ul>';
    	/* Restore original Post Data */
    	wp_reset_postdata();

    Using these args works:

    $myArgs = array(
       'post_type' => 'any'
    	        );

    I have 4 items: twos posts, a tribe event, & a page. Each one is returned. In the print_r return, it even shows the tribe event as being [post_type] => tribe_events

    When I change it to this:

    $myArgs = array(
       'post_type' => 'tribe_events'
    	        );

    Nothing works, nothing is returned. I would expect the one tribe event to be returned.

    It seems to not be triggering a “true” on have_posts(). Earlier I had it wrapped in an if statement like so…

    if ( $MyQuery->have_posts() ) {
        // do the loop
    }
    
    else {
    echo ("no posts!");
    }

    …and it was always echoing no posts when [post_type] => tribe_events

    I was aware of the tribe_get_events function. My issue is that I will eventually need to call in a loop from two different kinds of posts: regular ones & tribe events.

    One other possible concern? Although I am a paid “pro” calendar user on live sites, I’m working on this in a new dev environment and I haven’t gotten around to upgrading this particular install of the plugin. I eventually will re-buy it again and install it. Does it matter that this is the free version? (I would think not, but wanted to mention that so we can get the full picture.)

    Thanks so much for your input. Look forward to hearing if you have other thoughts.

    • This reply was modified 8 years, 8 months ago by stevevgl. Reason: (Just fixing some formatting)
    #1335064
    stevevgl
    Participant

    To add to this…

    No matter what I do, it remains consistent in the idea that the post_type of tribe_events just isn’t triggering a true on have_posts().

    To explain, I have two “events” and two regular “posts”.

    This works as expected:

    'post_type'=> array('post')

    • It returns the two posts, but not the events.
    • have_posts() evaluates to true

    This works as expected:

    'post_type'=> array('tribe_events','post')

    • It returns all four: the two regular posts and the two tribe_events. The two that are tribe events return a post_type of “tribe_events”.
    • have_posts() evaluates to true

    This does NOT work as expected (or at least as I expect it would):

    'post_type'=> array('tribe_events'')

    • Nothing is retuned.
    • have_posts() evaluates to false

    I am stumped.

    #1335324
    Jennifer
    Keymaster

    Hi Henry,

    Thanks for sharing that additional information! Could you try using

    'post_type' => 'tribe_events',
    'status' => 'any'

    and see if you are able to get any events that way? Also, could you send me screenshots showing the event details sections for the two events that you have?

    Thanks,

    Jennifer

    #1335388
    stevevgl
    Participant

    Jennifer,

    We’ve got it! As is often the case, as I poured over code looking for the most minute little issues that might affect things, it ended up being something much simpler.

    This is what clued me in…

    could you send me screenshots showing the event details sections for the two events that you have?

    I got to thinking, could it be something with the CONTENT and not the code? It was as simple as this…

    The dates of the two events had already passed and, apparently, the have_posts was only coming up true when it uses dates that are not in the past! I never thought of this since they came up among a regular post query. 🙂

    Thanks for all your help!

    #1336566
    Jennifer
    Keymaster

    Terrific! I’m glad you were able to get it figured out – and thanks for posting your solution here!

    I’ll go ahead and close out this thread, but please feel free to open a new one if you run into any further issues.

    Thanks,

    Jennifer

     

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Can\’t Seem to Use the Right Post Type’ is closed to new replies.