Unable to get Organizer Post ID (to filter using a meta_query)

Home Forums Calendar Products Events Calendar PRO Unable to get Organizer Post ID (to filter using a meta_query)

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #29365
    Will
    Participant

    Hey there,
    I’m setting up a loop on a template page to list off all custom post type objects EXCEPT one that has a Tribe Organizer attached to it.

    The organizer is attached to that custom post type using an Advanced Custom Field “Post Object”.

    I need to set up a meta_query to not show that one specific post that has that organizer attached to it.

    I totally have it working when I hardcode in the value of the Organizer’s ID. However, as soon as I move this site over to production, the IDs of the posts will all change, and my code will break. So I need to be able to get the Organizer’s ID programatically.

    I’ve tried using get_page_by_title(), get_page_by_path(), tribe_get_organizer_id(), and written my own functions to get ID by slug. However… the Organizer’s path, title, and slug aren’t necessarily the name of the organizer like I would have thought.

    How do I return the ID of the Organizer by it’s name field?

    I suppose a last ditch effort would be to do a totally separate query of the tribe_organizer post type and get it that way, but that seems like a waste of cycles. If there’s a way to get it by existing functions, that would be great.

    Thanks!

    #29368
    Barry
    Member

    Would this work for you? http://pastebin.com/rMvKjBzK

    #29369
    Barry
    Member

    For completeness, tribe_get_organizer() which optionally accepts a post ID (though it isn’t required if you’re in the loop) returns the organizer name, if one is set.

    #29380
    Will
    Participant

    tribe_get_organizer() would require the ID, which is what I need to return.

    The code on pastebin… it’s close. I used my get_ID_by_slug() function to grab the custom post that I attached the Organizer to via an ACF, but that won’t work, as it’s not using Tribe’s method of attaching an Organizer, because that page isn’t a Tribe event, it’s a custom post. I can continue whittling away, maybe eventually when I have an actual Tribe event created that uses that Organizer, I can get that event’s slug, then use your code to return the ID.

    What’s weird is that when I set up an ACF Post Object, the Organizer shows up as a post object: Tribe_Organizer. Is it not? If it is, shouldn’t there be a slug or “post name” for it?

    #29381
    Will
    Participant

    Nope, didn’t work even after creating an event and attaching an organizer to it. Though… there may be some crap code in here. I’ve been up all night, I should rest and look at this when I’m fresh.

    #29385
    Barry
    Member

    OK, my fault for making a big assumption there (that you were working inside the loop in something like the upcoming events list).

    Re-reading your first and later posts, I’m not actually 100% clear on what you are doing here, but why not rest up as you suggest and get back to me if you need clarification on anything at that point.

    Thanks!

    #29455
    Will
    Participant

    Got it Barry, yeah sorry. Late night/early morning posting tends to get fuzzy.
    I’ll try to break it down again:

    First: the future problem I’m dealing with: I’m working on a dev site, on a dev server. I will be migrating the theme and the actual content into an existing WP multisite. My experience is that when I do that, all the Post IDs change (because in a lot of cases the IDs are already taken by existing posts on production server). So I can’t hard code post IDs into functions or queries. I need to dynamically return them.

    Second: I need to filter out some posts on a custom post type archive page (NOT a Tribe Event) and not show posts that have a specific Tribe_Organizer attached to them. I attached the Tribe_Organizer using an Advanced Custom Field. That archive page, then, does not exist in the context of an Event Calendar page. It is its own custom post type archive page.
    (And, I already have that query working, as long as I hard-code the ID of the organizer. I do NOT need help with that.)

    The problem comes down to when I migrate the site over. This page will immediately break and display the posts associated with that one specific Tribe Organizer, because the post IDs will all change as soon as I migrate, and I have to hard code them right now.

    So, I need a method to return the Organizer’s ID by slug, or by name, on a page that is outside the context of the calendar. USUALLY, I would just do this using built in WP functions like get_page_by_path() or get_page_by_title(), and loop through the object and get the ID. But neither of these methods work with the Tribe_Organizer, because I have no idea what the slug of the Organizer’s page is, or what the Title of the Organizer’s page is. There’s no archive page for the Organizer, no slug field, no post title.

    So, my question is, how do I get that info? Or, how do I just return a post ID of an Organizer? I can dig through the MySQL database, and I’m about to do that, as that probably would have been faster than writing this, BUT… it may help someone else later who’s trying to do the same thing.

    Does that make sense?

    #29478
    Barry
    Member

    OK, so for getting the organizer from a slug you are going to have to go your own way on that one, it’s not something that we have a convenient function for. I knocked together this function and it shows one approach, but you might need to refine it a little.

    #29537
    Will
    Participant

    ooooh that looks pretty good. I’m going to take tonight off as two weeks straight of 16 hour days is wearing me down, but I’ll check back on Sat to let you know how it goes. Thanks so much for your help!!

    #29542
    Barry
    Member

    Not at all.

    #29933
    Will
    Participant

    Hey Barry,
    Hope you don’t mind, but I updated your pastebin function to a function (and a filter) that allow for the organizer ID to be returned based on the organizer’s string name.

    http://pastebin.com/sp5U5Hry

    Usage: if you have an organizer named “Will Lanni”:
    $org_id = get_organizer_id_by_title(“Will Lanni”);

    #29934
    Barry
    Member

    Good stuff, thanks for posting back your solution 🙂

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘Unable to get Organizer Post ID (to filter using a meta_query)’ is closed to new replies.