name = 'relationship'; $this->title = __("Relationship",'acf'); // actions add_action('wp_ajax_acf_get_relationship_results', array($this, 'acf_get_relationship_results')); } /* * my_posts_where * * @description: * @created: 3/09/12 */ function posts_where( $where, &$wp_query ) { global $wpdb; if ( $title = $wp_query->get('like_title') ) { $where .= " AND " . $wpdb->posts . ".post_title LIKE '%" . esc_sql( like_escape( $title ) ) . "%'"; } return $where; } /*-------------------------------------------------------------------------------------- * * acf_get_relationship_results * * @author Elliot Condon * @description: Generates HTML for Left column relationship results * @created: 5/07/12 * *-------------------------------------------------------------------------------------*/ function acf_get_relationship_results() { // vars $options = array( 'post_type' => '', 'taxonomy' => 'all', 'posts_per_page' => 10, 'paged' => 0, 'orderby' => 'title', 'order' => 'ASC', 'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'), 'suppress_filters' => false, 's' => '', 'lang' => false, 'update_post_meta_cache' => false, 'field_name' => '', 'field_key' => '' ); $ajax = isset( $_POST['action'] ) ? true : false; // override options with posted values if( $ajax ) { $options = array_merge($options, $_POST); } // WPML if( $options['lang'] ) { global $sitepress; $sitepress->switch_lang( $options['lang'] ); } // convert types $options['post_type'] = explode(',', $options['post_type']); $options['taxonomy'] = explode(',', $options['taxonomy']); // load all post types by default if( !$options['post_type'] || !is_array($options['post_type']) || $options['post_type'][0] == "" ) { $options['post_type'] = $this->parent->get_post_types(); } // attachment doesn't work if it is the only item in an array??? if( is_array($options['post_type']) && count($options['post_type']) == 1 ) { $options['post_type'] = $options['post_type'][0]; } // create tax queries if( ! in_array('all', $options['taxonomy']) ) { // vars $taxonomies = array(); $options['tax_query'] = array(); foreach( $options['taxonomy'] as $v ) { // find term (find taxonomy!) // $term = array( 0 => $taxonomy, 1 => $term_id ) $term = explode(':', $v); // validate if( !is_array($term) || !isset($term[1]) ) { continue; } // add to tax array $taxonomies[ $term[0] ][] = $term[1]; } // now create the tax queries foreach( $taxonomies as $k => $v ) { $options['tax_query'][] = array( 'taxonomy' => $k, 'field' => 'id', 'terms' => $v, ); } } unset( $options['taxonomy'] ); // search if( $options['s'] ) { $options['like_title'] = $options['s']; add_filter( 'posts_where', array($this, 'posts_where'), 10, 2 ); } unset( $options['s'] ); // filters $options = apply_filters('acf_relationship_query', $options); $options = apply_filters('acf_relationship_query-' . $options['field_name'] , $options); $options = apply_filters('acf_relationship_query-' . $options['field_key'], $options); $results = false; $results = apply_filters('acf_relationship_results', $results, $options); $results = apply_filters('acf_relationship_results-' . $options['field_name'] , $results, $options); $results = apply_filters('acf_relationship_results-' . $options['field_key'], $results, $options); if( ! $results ) { // load the posts $posts = get_posts( $options ); if( $posts ) { foreach( $posts as $post ) { // right aligned info $title = ''; $title .= $post->post_type; // WPML if( $options['lang'] ) { $title .= ' (' . $options['lang'] . ')'; } $title .= ''; // find title. Could use get_the_title, but that uses get_post(), so I think this uses less Memory $title .= apply_filters( 'the_title', $post->post_title, $post->ID ); // status if($post->post_status != "publish") { $title .= " ($post->post_status)"; } $title = apply_filters('acf_relationship_result', $title); $title = apply_filters('acf_relationship_result-' . $options['field_name'] , $title); $title = apply_filters('acf_relationship_result-' . $options['field_key'], $title); echo '