Custom Post type content not displaying on single page


I have added a select dropdown on my custom post type in the admin panel. Basically that is a select dropdown which is displaying my another custom post type title. I used below code.

$args = array( 'post_type'=>'blogauthor','post_status' => 'publish' );
    $recent_posts = wp_get_recent_posts($args);
    $getblogauthorId=get_post_meta(get_the_ID(), 'blogauthor', true );// get selected when hit URL page
    echo '<select name="blogauthor">
            <option  value="" selected="" disabled="">Select Author</option>';
    foreach( $recent_posts as $recent ){
        if($recent["ID"]==$getblogauthorId){ $authselected='selected="selected"';};
        echo'<option value="' .$recent["ID"].'" '.$authselected.'>' .   $recent["post_title"].'</option> ';

There is no issue with above dropdown.

Now I am on single page and I have to show the content which I selected from the drodpwn.
what is the issue with below code because every time it’s run else part.

$blogauthorId=get_post_meta(get_the_ID(), 'blogauthor', true );
        $the_query =array(
          'post_type' => 'blogauthor',
          'post_status' => 'publish',
          'numberposts' => 1,
          'meta_key' => 'blogauthor',
          'meta_value' => $blogauthorId,
          'order'      => 'DESC'
        $authorData = new WP_Query($the_query);
        if ($authorData->have_posts()): while($authorData->have_posts()): $authorData->the_post();
        endwhile; else:
        echo "Please select author";

user9437856 4 months 0 Answers 23 views 0

Leave an answer