Filter on State/Province field of Venue address

Home Forums Calendar Products Filter Bar Filter on State/Province field of Venue address

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1062557
    Keith
    Participant

    What would be the best way to achieve this? Do I need to create a custom field and then write code to copy the Province/State field into that field?

    #1063370
    George
    Participant

    Hey Keith!

    Apologies for the delayed reply here.

    Can you elaborate a bit more on exactly what you are trying to pull off here? You say, “What would be the best way to achieve this?” – can you clarify what it is specifically that you are trying to achieve?

    I can hopefully offer some insight from there – thank you Keith!

    — George

    #1063394
    Keith
    Participant

    Hi George,

    I’m pulling in a lot of events automatically. They have values in the State/Province field of the Venue address. I’d like users to be able to filer on that field. That is, I’d like them to be able to display only the events for venues in a particular province.

    As I see it, I can create a custom field called Province and add that to the filter bar. I would then have to manually edit every event to copy the value from the Venue address to the Province field. I would like to automate that process.

    Cheers,
    Keith

    #1064090
    George
    Participant

    I appreciate your elaboration on this Keith. I’m sorry to bear the news that what you are trying to do would require some extensive code customization which exceeds the scope of support we can provide. Check out the “Product Support” section of this page for more information on this → http://theeventscalendar.com/terms

    I’m sorry about this! What you are trying to do is technically possible, and it’s a feature we are hoping to include in the plugins as a new feature in one of our upcoming releases. But at this time it requires a hefty amount of customization 🙁 I’m sorry Keith.

    Please let me know what you think about this and if there’s anything else that I could try and help with.

    Sincerely,
    George

    #1064448
    Keith
    Participant

    Hi George,

    Thanks for the response. I realise that you don’t get involved in customization support. What I am a little surprised about is that you mention that what I want to do would require a substantial amount of coding.

    If we take for example the Facebook import hook that we talked about in the other thread (https://goo.gl/WuHJ5M), I was thinking that I could achieve what I’m wanting to do like this:

    1. Create an “Additional Field” called Province in the TEC Pro tab.
    2. Assign a function to the hook, as described in the other thread. That function would work as follows:

    Every time a Facebook event is stored to the database:

    1. Read it back and get the State/Province field from the venue address
    2. Update the Additional Field Province with the value read above. (is there a function that I can call to update an Additional Field?)

    (I’m making a distinction between what is referred to as an Additional Field in the TEC Pro tab, and the “Add Custom Field” box which is available when you’re editing an event. As I understand it, Additional Fields can be used in the Filter Bar whereas Custom Fields cannot).

    Cheers,
    Keith

    #1064507
    George
    Participant

    Hey Keith,

    Apologies for the lack of clarity on my part. While it might be an objectively “substantial” amount of code, all I mean is that it’s large-enough of a custom project that I couldn’t write just a simple snippet to achieve this.

    You are absolutely right that such a connection could happen based on an event import – to try and actually help here on a code-level, the hook you’re looking for is called tribe_events_facebook_event_created.

    An example of that hook in action would be this:


    function tribe_example( $event_id, $organizer_id, $venue_id ) {
    // the parsing and saving of location here...
    }

    add_action( 'tribe_events_facebook_event_created', 'tribe_example', 10, 3 );

    As you can see in the callback function, you have access to $event_id, $organizer_id, and $venue_id, so you can use these IDs to start pulling the content from venues and saving it to an event’s Additional Field.

    To help with the extraction of specific event data, check out this folder in your plugin files for The Events Calendar:

    the-events-calendar/src/functions/template-tags

    All of the files in this folder contain functions related to their filenames; so, venue.php contains venue-related functions which you can hopefully use to extract province and other address information.

    I hope this helps you get started with your customizations!

    Cheers,
    George

    #1064509
    Keith
    Participant

    Hi George,

    That’s great. Thanks. I was up to speed on the Facebook events hook, and I’ll go through the templates-tags folder. Just one more quick question, if I can. To actually update the Additional Field that I’m going to create, what function to do I need? That is, once I’ve retrieved the data from the Venue how do I write it to the Additional Field?

    Thanks for your help,
    Keith

    • This reply was modified 10 years, 2 months ago by Keith. Reason: typo date=>data
    #1064516
    George
    Participant

    That’s the tricky part, Keith – I haven’t tinkered this first-hand, but you should be able to use the WordPress function update_post_meta() without much issue. (You can read more about this function here → https://codex.wordpress.org/Function_Reference/update_post_meta

    The key for the meta field is something you’d have to use some tinkering to figure out – if you use var_dump() on some test events that you already populate that field for, you should be able to find the proper meta key to use.

    Best of luck with your customizations Keith!

    — George

    #1068011
    Keith
    Participant

    Hi George,

    I’ll look into writing something myself using update_post_meta but I’m thinking it might be easier to duplicate the existing code.

    For example, I’ve created an Additional Filed called provincia. That means that for any event I can manually add that field, like this: http://pasteboard.co/1kg82B0J.png.

    If you can point me to the code that gets executed when that field is updated, I think that might be the quickest way forward.

    Regards,
    Keith

    #1068584
    George
    Participant

    Hi Keith,

    I unfortunately cannot devote more time to assistance with customizations here; please see the “Product Support” section of this page for more information → http://theeventscalendar.com/terms

    I have tried to be helpful a bit outside the scope of those terms nonetheless, but at this point I unfortunately have to leave the reins in your hands. I’m sorry about that.

    Keep good backups of all custom code along the way for easy undoing of missteps; use Google liberally for anything you’re not sure about; and tinker around a bit. I’m sure you’ll be able to put together what you need!

    I will now close this thread–if other questions ever arise that are under the umbrella of the “Product Support” we can provide (as defined in the Terms I linked you to earlier), please open a new thread any time.

    Sincerely,
    George

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Filter on State/Province field of Venue address’ is closed to new replies.