Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Filters posts_where to add a "post_title_like" parameter to WP_Query
- *
- * Then Returns the post object for an organizer who should be identified
- * by organizer's title.
- *
- * If the organizer cannot be found (bool) false will be returned.
- *
- * @param $title
- * @return bool|object
- */
- function title_like_posts_where( $where, &$wp_query ) {
- global $wpdb;
- if ( $post_title_like = $wp_query->get( 'post_title_like' ) ) {
- $where .= ' AND ' . $wpdb->posts . '.post_title LIKE \'' . esc_sql( like_escape( $post_title_like ) ) . '%\'';
- }
- return $where;
- }
- add_filter( 'posts_where', 'title_like_posts_where', 10, 2 );
- function get_organizer_id_by_title($title) {
- $args = array(
- 'post_title_like' => $title,
- 'post_type'=> TribeEvents::ORGANIZER_POST_TYPE
- );
- $query = new WP_Query($args);
- if ($query->have_posts()) {
- $query->the_post();
- $post = $query->post;
- wp_reset_query();
- return $post->ID;
- }
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment