It might be easier if you explain what you want to do instead of how you want to do it, usually there is a much simpler way that you’ve might have overlooked.
The only information I can find keeps pointing to the query object and is more appropriate for plugins. Is this possible from a theme?
Yes. Put the code in the theme’s functions.php file. This code is loaded in a way very similar to a plugin, and it’s how themes can define custom code.
I would like to add a query variable to further define a custom query on a single page.
add_filter('query_vars', 'add_my_var');
function add_my_var($public_query_vars) {
$public_query_vars[] = 'some_unique_identifier_for_your_var';
return $public_query_vars;
}
OK.
Essentially, I have a single page that lists books. Each book is a post in a single category. Furthermore, those posts have 1 or multiple tags.
For example,
Microsoft Office Outlook 2007
tags, outlook, office, and 2007
This page template by default lists all posts in this category. All is fine so far. What I would like to do, is use URL links in a navigation menu to filter those results.
So, if they click on a link that says, Outlook 2007, I would like to change my query for this page to only display those posts that are have tags of 2007 and Outlook.
If I use the example above, can I just add the query var to the permalink and then use the get_query_vars to parse out the details I need?
Once the query var has been added like I show above, then you can append it to any URL (as a GET variable, like ?my_var=whatever) and receive its value back anywhere you like:
$myvalue=get_query_var('my_var');
echo $myvalue; // outputs "whatever"
Note that of course you can bypass all this and just use $_GET and $_REQUEST and such, but with a query_var, you can also make use of the internal rewrite functions and thus integrate your var right into the URL, if you so choose.