Support

Home Forums Event Espresso Premium Filter Event Admin List Search Query

Filter Event Admin List Search Query

Posted: May 30, 2017 at 7:48 am

Viewing 6 reply threads


bewegt

May 30, 2017 at 7:48 am

Is there a way to search a custom metabox in the Event Admin List?
I added a custom column and I would like to search for its content.


// Add column "Kurs-ID" to the Event Table List
function my_event_table_head( $defaults, $screen) {
	if ( $screen != 'espresso_events_default' ) {
        $defaults[]  = ''; // Entfernt die Funktion wenn es nicht die default screenpage ist
		return $defaults;
    }
    unset($defaults['id']);
	unset($defaults['name']);
	unset($defaults['venue']);
	unset($defaults['start_date_time']);
	unset($defaults['reg_begins']);
	unset($defaults['attendees']);
	unset($defaults['actions']);
    
    
	$defaults['name']  = __( 'Name', 'event_espresso' );
    $defaults['kurs']  = __( 'Kurs-ID', 'event_espresso' );
	$defaults['venue']  = __( 'Venue', 'event_espresso' );
	$defaults['start_date_time']  = __( 'Event Start', 'event_espresso' );
	$defaults['reg_begins']  = __( 'On Sale', 'event_espresso' );
	$defaults['attendees']  = '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>';
	$defaults['actions']  = __( 'Actions', 'event_espresso' );
	$defaults['id']  = __( 'ID', 'event_espresso' );
	
    return $defaults;
}
add_filter( 'FHEE_manage_toplevel_page_espresso_events_columns', 'my_event_table_head', 10, 2 );
 

// Add content to the column "Kurs-ID"
function my_event_table_content( $event, $screen ) {
    if ( ! $event instanceof EE_Event ) {
        return '';
    }
	$taxonomy = 'espresso_event_categories';
	$terms = get_the_terms( (int) $event->ID(), $taxonomy );
	if( !empty( $terms ) ) {
		foreach( (array) $terms as $order => $term ) {
			if ($term->parent != 0) { // avoid parent categories
			$term_id = $term->term_id;
			$category = EEM_Term::instance()->get_one_by_ID($term_id);
			$category_kuerzel = $category->get_extra_meta( 'category_kuerzel', true ) . get_post_meta($event->ID(), "meta-box-text", true);
			echo $category_kuerzel;
			}
		}
	}

}
add_action( 'AHEE__EE_Admin_List_Table__column_kurs__toplevel_page_espresso_events', 'my_event_table_content', 10, 2 );


Josh

  • Support Staff

May 30, 2017 at 12:09 pm

Hi there,

This is possible but you’ll need to add the search box to another admin route. So step 1 is you add the following:

https://wordpress.stackexchange.com/a/16641

Then you can make the native custom post type route for Event Espresso events visible by adding:

https://gist.github.com/joshfeck/fa45f6d23219de88c9679c1397e5fbfa

You can add both of the above to a functions plugin.


bewegt

June 2, 2017 at 2:36 am

Thanks for your reply, but can’t I use just the normal Search Field for query the new column value like in the screenshot?Screenshot

Thanks for your help.


Tony

  • Support Staff

June 2, 2017 at 6:15 am

The search field queries the DB, the additional column you’d added concatenates an extra meta value from the events category and also event meta together within the column so 2 values. How are you going to query for those concatenated values on a single event?

The ‘WHERE’ conditions for the query are filtered so you can change how they are constructed if you can do the above:

apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data);

Another option you have is to just use the post meta value rather than the concatenated full value. You’ll likely want to take a look at the documentation available here for information on how to query the additional field using our models:

https://github.com/eventespresso/event-espresso-core/tree/master/docs/G–Model-System


Josh

  • Support Staff

June 2, 2017 at 7:26 am

Something like this will get you closer:

https://gist.github.com/joshfeck/9a38f938e940d7c36656320a04e7ff37

That said, the above will search for the post meta value. Your column’s content appears to be the combination of a category meta value + a post meta value so the results may vary.


bewegt

June 8, 2017 at 12:04 am

Thank you so much, it worked like a charm. I re coded the metabox to just one value so there is no Problem with the search query.

Is there also a filter available for the espresso_registrations page?


Josh

  • Support Staff

June 8, 2017 at 8:13 am

Hi there,

I checked and there isn’t a filter for the registrations search query. I can encourage you to add a filter to the _add_search_to_where_conditions() method and submit a pull request on the Github repository and the dev team will review:

https://github.com/eventespresso/event-espresso-core/

Viewing 6 reply threads

The support post ‘Filter Event Admin List Search Query’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso