Site icon Hip-Hop Website Design and Development

writer.php not exhibiting content material if Writer has no Posts

I’m making a customized Genesis theme, and have a customized writer.php file that pulls in numerous customized fields (Utilizing Superior Customized Fields), and writer meta info to the web page from the writer profile web page… It additionally shows their newest posts.

This works completely, IF the writer has posts assigned to them. If they do not, the web page does not output any of the content material that’s usually pulled from the authors profile…

I’ve searched StackExchange, and while this has been talked about a couple of instances, I can not seem to discover a solution that works.

I want the writer.php web page to output the writer info whether or not the person has posts or not. If they do not, the profile meta and customized fields ought to nonetheless show, and the current posts part mustn’t present any posts in it.

Here is my writer.php code.

// take away Genesis default loop
remove_action( 'genesis_loop', 'genesis_do_loop' );

// Take away Header Markup
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_open', 5 );
remove_action( 'genesis_entry_header', 'genesis_entry_header_markup_close', 15 );
remove_action( 'genesis_entry_header', 'genesis_do_post_title' );
remove_action( 'genesis_before_loop', 'genesis_do_author_title_description', 15 );

//take away the default sidebar widget setup
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
remove_action( 'genesis_sidebar_alt', 'genesis_do_sidebar_alt' );

// Add within the structure sections
add_action('genesis_loop','add_top_author_section');
add_action('genesis_sidebar','add_sidebar_info');
add_action('genesis_after_content_sidebar_wrap', 'add_latest_posts');


operate add_top_author_section() { 
    //vars
        $avatar = get_avatar( get_the_author_meta( 'ID' ), apply_filters( 'th_author_bio_avatar_size', 300 )  );
        $display_name = get_the_author_meta( 'display_name' );
    ?>
    <div class="author-details">
            <div class="left-profile">
                <?php echo $avatar; ?>
            </div>
            <div class="right-profile">
                <h2><?php echo $display_name; ?></h2>
                <p><?php the_author_meta('description'); ?>
            </div>
    </div>
<?php
}

operate add_sidebar_info() {  

    // Cuisines
    $user_id = get_the_author_meta( 'ID' );
    $display_id = 'user_'.$user_id;

    $phrases = get_field('types_of_cuisine2', $display_id);

    if ( $phrases ) { 
        echo '<div class="widget-sidebar-section cuisines"><h2>Cuisines</h2>';
        foreach ( $phrases as $time period ) :?>
            <a href="http://tastehaus.flywheelsites.com/recipes/?_sfm_cuisine=<?php echo $time period; ?>"><?php echo $time period; ?></a>

        <?php endforeach; 
        echo '</div>';
        } 

    // Based mostly In
    echo '<div class="widget-sidebar-section based-in"><h2>Based mostly In</h2>';
    the_field('based_in', $display_id); 
    echo '</div>';

    // Standing
    echo '<div class="widget-sidebar-section standing"><h2>Standing</h2>';
    the_field('standing', $display_id); 
    echo '</div>';  

    // Signature Dish
    echo '<div class="widget-sidebar-section sig-dish"><h2>Signature Dish</h2>';
    the_field('signature_dish', $display_id); 
    echo '</div>';  

    // Amazon Retailer Button
    ?>
    <a href="<?php the_field('amazon_store_link', $display_id);?>"><button>See My Really helpful Instruments</button> </a>
<?
}


operate add_latest_posts() { 

    echo '<div class="user-latest-posts">';
    echo '<h2 type="text-align:middle;">Latest Posts by '.  get_the_author_meta( 'first_name' ) .'</h2>';
    echo '</div>';

    world $put up;
    // arguments, alter as wanted
    $args2 = array(
        'writer'            =>  get_the_author_meta( 'ID' ), 
        'post_type' => array( 'recipes', 'instruments', ), 
        'orderby'           =>  'post_date',
        'order'             =>  'ASC',
        'posts_per_page'    =>  6,
    );
    /* 
    Overwrite $wp_query with our new question.
    The one purpose we're doing that is so the pagination features work,
    since they use $wp_query. 
    */
    world $wp_query;
    $wp_query = new WP_Query( $args2 );
    if ( have_posts() ) : 
        echo '<div class="posts-query">';
        whereas ( have_posts() ) : the_post(); ?>
                <div class="query-post">
                        <div class="query-padding">
                            <div clss="posts-image">
                                <?php the_post_thumbnail("thumbnail");?>
                            </div>
                            <div class="post-categories">
                            <?php $postType = get_post_type_object(get_post_type());
                                if ($postType) {
                                echo esc_html($postType->labels->singular_name);
                                } 
                            ?>
                            </div>                          
                            <div class="posts-title">
                                <a href="<?php the_permalink(); ?>">
                                    <h3> 
                                        <?php the_title() ?>
                                    </h3>
                                </a>
                            </div>
                        </div>
                    </div>
        <? endwhile; 
        echo '</div>';
        do_action( 'genesis_after_endwhile' );
    endif;
    wp_reset_query();
}
genesis();