SHARE
TWEET

Untitled

wlanni Dec 22nd, 2012 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Filters posts_where to add a "post_title_like" parameter to WP_Query
  3.  *
  4.  * Then Returns the post object for an organizer who should be identified
  5.  * by organizer's title.
  6.  *
  7.  * If the organizer cannot be found (bool) false will be returned.
  8.  *
  9.  * @param $title
  10.  * @return bool|object
  11.  */
  12.  
  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 $where;
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top