get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_title = %s AND post_type = %s {$in_clause}", $link_page, bp_docs_get_post_type_name() ) ); // If none were found, do the same query with page slugs if ( empty( $docs ) ) { $docs = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE post_name = %s AND post_type = %s {$in_clause}", sanitize_title_with_dashes( $link_page ), bp_docs_get_post_type_name() ) ); } // Filter the docs. This will be used to exclude docs that do not belong to a group $docs = apply_filters( 'bp_docs_bracket_matches', $docs ); if ( !empty( $docs ) ) { // If we have a result, create a link to that page // There might be more than one result. I guess we take the first one $doc = $docs[0]; $permalink = get_permalink( $doc ); $class = 'existing-doc'; } else { // If no result is found, create a link to the edit page $permalink = add_query_arg( 'create_title', urlencode( $link_page ), bp_docs_get_create_link() ); $class = 'nonexistent-doc'; } return apply_filters( 'bp_docs_bracket_link', '' . $link_text . '' ); } } ?>