I'm still new to wordpress and I'm trying to write a plugin but for some reason this code is producing nothing. Why? I am completely stumped. I have followed the examples here to a tee.

    Plugin Name: Text

    add_action("init", "init_stuff");

    function x_get_event_posts(){
        $all_events = tribe_get_events(
                'eventDisplay' => 'all',
                'posts_per_page' => -1,
                'tax_query'=> array(
                        'taxonomy' => 'tribe_events_cat',
                        'field' => 'slug',
                            'terms' => 'xmlworkshopdonotuse'

        echo count($all_events); // produces "0";

    function init_stuff() {

  • 1
    Are there actually published events in the xmlworkshopdonotuse category? – Pat J May 27 '13 at 19:08
  • yes, 77 to be exact. actually any query using tax_query returns 0 results. Also, interestingly, get_terms returns a WPError. – Tyler Johnson May 28 '13 at 0:53
  • That is odd, in light of the Codex's page on [get_terms()] saying that it will return false or a row from the DB. How are you calling get_terms() that it's returning a WP_Error? – Pat J May 28 '13 at 2:54

Okay so it turned out to be that I was using the incorrect action name. I changed "init" to "wp_loaded" in add_action() and that did the trick.

| improve this answer | |
  • Great... any chance you can mark your answer as correct so we can close out this question? – Adam Mar 9 '16 at 12:14
  • Just a note to anyone who may find this still doesn't work - the code in the original post does work BUT it will only show upcoming (future) events. – Andrew Oct 13 '18 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.