0

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.

<?php
    /*
    Plugin Name: Text
    */

    add_action("init", "init_stuff");

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

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

    function init_stuff() {
        x_get_event_posts();
    }

?>
3
  • 1
    Are there actually published events in the xmlworkshopdonotuse category?
    – Pat J
    Commented May 27, 2013 at 19:08
  • yes, 77 to be exact. actually any query using tax_query returns 0 results. Also, interestingly, get_terms returns a WPError. Commented May 28, 2013 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
    Commented May 28, 2013 at 2:54

1 Answer 1

1

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.

2
  • Great... any chance you can mark your answer as correct so we can close out this question?
    – Adam
    Commented Mar 9, 2016 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
    Commented Oct 13, 2018 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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