Separate custom post type by custom taxonomy term for author template
-
I am WP noob and am looking for a way to do the following: – Display specific custom post type “photograph” – Separate results by tax term – This needs to be displayed on custom author template for $curauth
I have searched high and low with no avail. There are results for each point separately, but nothing that brings it all together.
I found this function that fetches custom post type names for $curauth and displays them, maybe there is a way to tailor it to my request.
function get_author_post_types( $author_id = false ) { $results = array(); if ( $author_id ) { $post_types= get_post_types( array( 'public' => true ), 'names', 'and' ); $post_types = array_keys( $post_types ); $sql = array(); global $wpdb; $sql[] = "SELECT DISTINCT post_type FROM $wpdb->posts WHERE post_author = %d AND (post_status = 'publish') AND post_type IN(".implode( ', ', array_fill( 0, count( $post_types ), '%s' ) ).")"; $sql[] = $author_id; $sql = array_merge( $sql, $post_types ); $query = call_user_func_array( array( $wpdb, 'prepare' ), $sql ); $results = $wpdb->get_results( $query ); if ( $results ) $results = wp_list_pluck( $results, 'post_type' ); } return $results;
I am seriously desperate, and would very much appreciate any help or direction with this.
Thanks in advance.
- The topic ‘Separate custom post type by custom taxonomy term for author template’ is closed to new replies.