Lego2012
12/13/2016 - 4:25 PM

Include a note in entry content if the user is not logged in

Include a note in entry content if the user is not logged in

<?php
//* Do NOT include the opening php tag shown above. Copy the code shown below.

add_action( 'genesis_entry_content', 'user_post_list' );
function user_post_list() {

    if ( ! is_user_logged_in() ) :

        echo 'You must be logged-in to view your submitted questions and answers.';

        // wp_login_form();

    else :

        $current_user = wp_get_current_user();
        $display_name = $current_user->display_name;
        $authorID     = $current_user->ID;

        // List Open Questions
        echo '&nbsp;';
        echo '<h4>Your Open Questions:</h4>';

        // Search Categories Section Header

        echo '<div class="user-question-item">';

        $args = array(
            // 'orderby' => 'title',
            // 'order' => 'ASC',
            'post_type'      => 'os_support_question',
            'author'         => $authorID,
            'meta_key'       => 'ticket_status',
            'meta_value'     => 'open',
            'posts_per_page' => - 1
        );

        // The Query
        $open_query = new WP_Query( $args );

        // Set posts to display as unordered list
        echo '<ul>';

        // Each item displays Title with link to post
        while ( $open_query->have_posts() ) {
            $open_query->the_post();
            echo '<li class="article-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
        }
        echo '</ul>';


        // List Closed Questions
        echo '&nbsp;';
        echo '<h4>Your Answered Questions:</h4>';

        // Search Categories Section Header

        echo '<div class="user-question-item">';

        $closed_args = array(
            // 'orderby' => 'title',
            // 'order' => 'ASC',
            'post_type'      => 'os_support_question',
            'author'         => $authorID,
            'meta_key'       => 'ticket_status',
            'meta_value'     => 'closed',
            'posts_per_page' => - 1
        );

        // The Query
        $closed_query = new WP_Query( $closed_args );

        // Set posts to display as unordered list
        echo '<ul>';

        // Each item displays Title with link to post
        while ( $closed_query->have_posts() ) {
            $closed_query->the_post();
            echo '<li class="article-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
        }
        echo '</ul>';





        /* Restore original Post Data */
        wp_reset_postdata();

        echo '</div><!-- .user-question-item -->';

    endif;
}