WordPress query vars are not added

I’m currently trying to figure out how to get my custom url rewrites working (WP Rewrite the last two parts of the URL), while doing this I came across the following problem:

I have made a custom plugin (OOP) and I’m trying to add query variables to the public wordpress query variables list.

Read More

The code I use is the following:

/**
     * Adding the trainingid var so that WP recognizes it, this is being called on the query_vars filter in the constructor.
     * @param $vars the variables coming from the filter
     * @return the same variables with the plugins query vars appended.
     */
    function my_insert_query_vars($vars)
    {
        // Push the query var id in the $vars array
        array_push($vars, 'trainingid');
        return $vars;
    }

But when I execute the following code via a shortcode on a page the array printed does not contain trainingid.

global $wp_query;
var_dump($wp_query->query_vars);

Could anybody tell me what I am doing wrong?

Related posts