Custom field filter not searching

Home Forums Calendar Products Events Calendar PRO Custom field filter not searching

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #151150
    synapse
    Participant

    I have set up a few custom fields. I am trying to add a filter to the search bar for one of them, but when I enter something in to do the search by that filter, it doesn’t seem to insert that field into the query. The custom field is named “Sport” in the WP Event Calendar settings.

    The code is as follows:
    function setup_sport_field_in_bar($filters) {
    $filters[‘tribe-bar-sport’] = array(
    ‘name’ => ‘tribe-bar-sport’,
    ‘caption’ => ‘sport’,
    ‘html’ => ‘<input type=”text” name=”tribe-bar-sport” id=”tribe-bar-sport”>’
    );
    return $filters;
    }

    function setup_sport_field_in_query($query) {
    if (!empty($_REQUEST[‘tribe-bar-sport’])) {
    $query->query_vars[‘tribe-bar-sport’] = $_REQUEST[‘tribe-bar-sport’];
    //print_r($query->query_vars);
    }
    return $query;
    }

    add_filter(‘tribe-events-bar-filters’, ‘setup_age_field_in_bar’, 1, 1);
    add_filter(‘tribe-events-bar-filters’, ‘setup_sport_field_in_bar’, 1, 1);

    The

    #151817
    Barry
    Member

    Hi – great question!

    It’s awesome to see people building neat stuff like this but I have to be upfront and say that there is a limit to just how much help we can provide with customizations at this comparatively advanced sort of level.

    if (!empty($_REQUEST['tribe-bar-sport'])) {
        $query->query_vars['tribe-bar-sport'] = $_REQUEST['tribe-bar-sport'];
        //print_r($query->query_vars);
    }

    I can see you’re thinking here, but the problem is that a query variable of tribe-bar-sport is not something WordPress/The Events Calendar can understand. It’s definitely worth reading up on the WP Query docs in the first instance here to get some insight into how WordPress itself handles queries.

    You’re probably going to be particularly interested in the custom field/meta query portion of those docs and a lot can be learned by looking at how we store the additional fields … it’s not quite as it is with regular WordPress custom fields for posts (the meta key naming convention results in key names like _ecp_custom_n for instance, in the case of our own additional fields).

    I hope that helps – and good luck 🙂

    #601003
    Motorco
    Participant

    Okay so I am in a similar situation. I have added some “additional fields” and I want to use these. For one, I am just adding additional data to be displayed as part of the event. But for another, I would like to specify how an event is displayed in the loop using tribe_get_events. The latter is (embarrassingly), a mystery to me. As an aside, how does ‘eventDisplay’ => ‘upcoming’ work? I don’t get how that gets passed to WP_query and yields a meaningful result? But it does – if I get rid of it, then I get old events. There is, as far as I can see, nothing in post_meta called “eventDisplay”.

    So similarly, if I add ‘_ecp_custom_1’ => ‘true’ to the list of $args passed to tribe_get_events, I should get only events where that additional field is set to true. But instead, it is completely ignored. Sort of the opposite of the above since there *is* an entry for “_ecp_custom_1” in my post_meta with a handful of events with it set to true. There is some magic happening that is elusive. Help?

    #674548
    Motorco
    Participant

    Still stuck on this….

    #701505
    Barry
    Member

    Hi Mike,

    Apologies for missing this. Unfortunately, until recently, posts made by people other than the original poster did not result in the team being notified of a follow-up (and generally we do ask that you create a new thread of your own, regardless of how similar the issue may be).

    If you still need help with this please go ahead and create a new thread – but do bear in mind, as in synapse’s case, we are fairly limited in terms of how much support we can offer for custom development task.

    Thanks again 🙂

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Custom field filter not searching’ is closed to new replies.