Custom Taxonomy Template

Home Forums Calendar Products Events Calendar PRO Custom Taxonomy Template

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #70909
    enollo
    Participant

    My project requires the use of a custom taxonomy to further filter events. Let’s call this taxonomy ‘department’.
    So far I have created a template file in my theme name taxonomy-department.php pasted in the following

    EDIT: The forum failed me. It is not allowing me to post the code. Here’s a version with the php tags stripped
    tribe_events_before_html();
    tribe_get_view(‘map’);
    tribe_events_after_html();

    To get all the right scripts and styles enqueued I hooked into the following filters making sure they return true if `is_tax(‘department’)`
    `tribe_query_is_event_query`
    `tribe-events-bar-should-show`

    There is still a bit more to do as the view filters don’t link to this custom taxonomy, and the pagination doesn’t work but I have an even weirder problem. This setup is not using the custom template I have set up in my theme in `tribe-events/pro/map.php`.

    Another thing I’ve noticed is that some of the CSS styles aren’t applied as the content is not wrapped in #tribe-events-content-wrapper, but I have yet to hunt the code for an appropriate filter to make the `tribe_events_before_template` and `tribe_events_after_template` actions fire.

    What steps are required to use a custom taxonomy with your templates and are they outline anywhere? Do you suggest any best practices for using custom taxonomies with the tribe_events post type? Would custom fields make my life easier? What would be the process there?
    I would prefer not to use custom fields as I’d like pretty permalinks.

    Thanks for your time

    #71016
    enollo
    Participant

    I have ditched the template idea and have instead filtered the rewrites to include my custom taxonomy (using tribe_events_rewrite_rules). I also filtered the links using the tribe_events_getLink filter.
    I was very excited for a while because it looked like it worked until I realized AJAX calls do not seem to apply my link filters and so pagination links revert back to original as soon as I switch a page. I hunted through the code and found that, for example, TribeEvents::calendar_ajax_call is what handles the ajax response for the month view. I was shocked to find that query_posts is being used and the only filter I am able to use is on the response itself. I would love a filter on the $query_args array so that I can add my custom taxonomy when required. Or at least don’t replace the query all together and only replace the variables that change.

    [rant]
    I must say that my relationship with this plugin has been a love-hate one. I love all of the things it can do and still firmly believe it is the best plugin for the job. But, hunting through the code to find what I need it to do has left a sour taste in my mouth. The documentation I could find was fine, but seems to not cover a lot of possibilities. The support forum is riddled with answers such as “that level of customizability is not covered by our standard support”. While I respect that $50 does not cover customizations, it would be great if we can pool the community together and post tips and tricks covering problems others have solved. Why not add a tips and tricks area to the forum where the topics never get closed and we can continue discussing at will?

    Adding a custom taxonomy to a post type registered by a plugin should not be considered a high level of customization. I understood there would be some hoops to jump through, and that is fine give the functionality this plugin brings. I just wish it was as easy as adding an attribute to a product in WooCommerce is. Or at least a codex page covering the necessary steps required to do this.
    [/rant]

    Thanks for taking the time to listen to my questions, suggestions and rants 😉

    #71017
    enollo
    Participant

    Nevermind about the query_posts. It’s late and I have been staring at code all day long. There is no access to the current query in the ajax hook it seems.

    Is there a way to disable ajax completely? I think that would be a temporary solution until I figure out how to pass in the correct query vars to the ajax call.

    Thanks

    #71093
    Barry
    Member

    Hi Enollo,

    It sounds like you’re doing some interesting work here – and it’s always great to hear about things like this being built on top of The Events Calendar 🙂

    You’re quite correct however that the forum currently doesn’t do a great job of handling posted code – so we’d generally recommend that, at least until we can add a better system for dealing with code, you use a service like Pastebin or Gist and simply drop the link to your snippet in here.

    I was shocked to find that query_posts is being used and the only filter I am able to use is on the response itself. I would love a filter on the $query_args array so that I can add my custom taxonomy when required.

    A number of filters and actions are implemented by the WP_Query object itself and so there should be scope to manipulate things here, even if the arguments passed in via query_posts() (within TribeEvents::calendar_ajax_call() ) are not directly filterable.

    Is there a way to disable ajax completely? I think that would be a temporary solution until I figure out how to pass in the correct query vars to the ajax call.

    You could try selectively dequeuing the relevant scripts that add ajax capabilities – but do take care in case that also removes other functionality. An alternative could be to use a script of your own to trap certain events and stop their onward propagation.

    You’re right that there is a very real limit on how much support we can offer for customizations and we definitely appreciate that can cause some amount of frustration at times. What I would say is, you’re very welcome to post tips and snippets right here in this forum (and others have certainly done the same) – a specific Tips and Tricks forum is definitely a good idea and we’d welcome feature requests for this sort of thing just as much as we do for the software itself:

    http://tribe.uservoice.com

    Thanks!

    #71115
    enollo
    Participant

    HI Barry,

    Thanks for your response 🙂 I will sure checkout the uservoice forum later today.

    The issue I am having is not that the filters are not applied, is that my check to see if we are current viewing a term in my custom taxonomy fails. AJAX is something that I have strategically avoided in my career, so going through your code has forced me to try to learn it 🙂 Anyway, looking at your JS files I can see you had the same “issue” and had approached it in a clever way using data attributes in the HTML. Your implementation of passing the category gave me an idea in my head of how to approach it and was wondering if you guys will be open to adding a filter on the $query_args array before it is sent to query_post() ?

    I think if I can figure this out I would be able to provide you guys and the community with the final code in the form of an extension.

    For the time being if anyone is wondering what I was wondering initially, here is what I found out:
    Let’s say your taxonomy is named ‘departments’. You will not get very far with following the standard WP template hierarchy by creating taxonomy-departments.php. Instead we can observe the following:
    The standard taxonomy pretty permalink
    http://example.com/departments/hr

    Simply adding some query vars to the link will grab the Events Calendar template:

    http://example.com/departments/hr/?post_type=tribe_events&eventDisplay=month

    Since you can’t expect your users to type that out we can use the term_link and tribe_events_getLink filters to append the query string to the links:

    http://pastebin.com/kU6pcQW9

    The term_link filter will ensure however you add a link to your taxonomy, the query args will be appended. In my case, this custom taxonomy is a huge part of the project and links to the terms are added to the main nav menu. That filter did all the work for me 🙂

    I also addressed the pretty permalink thing (and amended the filters to take that into account) but it’s a little messy and not ready for prime-time just yet. If this thread stays open, I will definitely post it here for anyone looking for a similar solution.

    As I said, these few small steps makes it almost work. AJAX get’s in the way and I am fighting with it as we speak

    #71179
    enollo
    Participant

    Hi again,

    So sorry to flood the forum. I am usually the customer that either sits in the background reading support threads but never asking questions, or the one who answers them just for fun so this is a new experience for me.

    I have a “feature request” related to the above. I’d like to have the following filters added to an upcoming release if at all possible. Please notify me if this request gets approved or rejected so that I can plan my update practice accordingly.

    https://gist.github.com/tamarazuk/4bfcbe52010e9ef443c2

    Thanks

    #71345
    Barry
    Member

    We’re always happy to consider feature requests – to ensure it is correctly annotated and runs through our usual workflow however can I ask you to post your request on our Uservoice page:

    tribe.uservoice.com

    By all means link back to this thread if it makes it easier to explain the idea. Thanks! It sounds like a very interesting project.

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Custom Taxonomy Template’ is closed to new replies.