SHOW:
|
|
- or go back to the newest paste.
1 | /** | |
2 | - | * Returns the post object for an organizer who should be identified |
2 | + | * Filters posts_where to add a "post_title_like" parameter to WP_Query |
3 | - | * by slug. |
3 | + | * |
4 | * Then Returns the post object for an organizer who should be identified | |
5 | * by organizer's title. | |
6 | * | |
7 | - | * @param $slug |
7 | + | |
8 | * | |
9 | * @param $title | |
10 | - | function get_organizer_by_slug($slug) { |
10 | + | |
11 | - | $query = new WP_Query("name=$slug&post_type=".TribeEvents::ORGANIZER_POST_TYPE); |
11 | + | |
12 | ||
13 | - | // Successful query? Return the first object if so (we anyway expect the slug to be unique) |
13 | + | function title_like_posts_where( $where, &$wp_query ) { |
14 | global $wpdb; | |
15 | if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) { | |
16 | $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( $post_title_like ) ) . '%\''; | |
17 | } | |
18 | - | return $post; |
18 | + | return $where; |
19 | - | } |
19 | + | } |
20 | add_filter( 'posts_where', 'title_like_posts_where', 10, 2 ); | |
21 | ||
22 | function get_organizer_id_by_title($title) { | |
23 | $args = array( | |
24 | 'post_title_like' => $title, | |
25 | 'post_type'=> TribeEvents::ORGANIZER_POST_TYPE | |
26 | ); | |
27 | $query = new WP_Query($args); | |
28 | if ($query->have_posts()) { | |
29 | $query->the_post(); | |
30 | $post = $query->post; | |
31 | wp_reset_query(); | |
32 | return $post->ID; | |
33 | } | |
34 | else return false; | |
35 | } |