I've created a new custom post type called doctors
. I've been using ACF and pulling these fields to help create my banner. I was wondering what a post would look like if no fields were filled out, so I created a second test post, but I noticed it has all of the same content as my first post.
I feel like I'm writing my function incorrectly, obviously.
function doctor_banner_shortcode() {
$args = array(
'posts_per_page' => 1,
'post_type' => 'doctors',
'post_status' => 'publish'
);
$doctors_query = new WP_Query( $args );
if ( $doctors_query->have_posts() ) :
while ( $doctors_query->have_posts() ) :
$doctors_query->the_post();
$dr_name = get_field( 'practitioner_name' );
$dr_degree = get_field( 'practitioner_title' );
$dr_bio = get_field( 'practitioner_short_bio' );
$dr_cv = get_field( 'practitioner_cv' );
$html_out = '<h1>Dr. ' . $dr_name . '</h1>
<h3">' . $dr_degree . '</h3>
<p>' . $dr_bio . '</p>
<a href="' . $dr_cv . '">' . 'Read CV' . '</a>';
endwhile;
else : // No results
$html_out = "No Doctors Found.";
endif;
wp_reset_query();
return $html_out;
}
add_shortcode( 'doctor_banner', 'doctor_banner_shortcode' );
Somehow, I think, it's not reading the proper ID of that post to output the correct data. I have two links for my two posts here and here.