I have two different post types where I want to have a relationship. Authors can list one business(post type - "listings") and many special offers (post type - "special_offers"). In each single special offer page, I need to display which business offers that specific offer. Currently I'm using this code, and it outputs the Business name correctly. I need the business logo to be there as well (featured image)
function get_author_business() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post_type' => 'listings', 'post__not_in' => array( $post->ID ), 'posts_per_page' => -1 ) );
foreach ( $authors_posts as $authors_post ) {
$output .= '<a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
return $output;
}
This might help (i'm assuming you are trying to get the image tag inside your output html)
function get_author_business() {
global $authordata, $post;
$authors_posts = get_posts( array( 'author' => $authordata->ID, 'post_type' => 'listings', 'post__not_in' => array( $post->ID ), 'posts_per_page' => -1 ) );
foreach ( $authors_posts as $authors_post ) {
$business_img = wp_get_attachment_image_src( get_post_thumbnail_id( $authors_post->ID ), 'thumbnail' );
$output .= '<img src="'.$business_img[0].'"><a href="' . get_permalink( $authors_post->ID ) . '">' . apply_filters( 'the_title', $authors_post->post_title, $authors_post->ID ) . '</a>';
}
return $output;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments