Skip to content

Instantly share code, notes, and snippets.

@craiggrella
Last active August 29, 2015 14:07
Show Gist options
  • Save craiggrella/a4c50dc68d78b9801ba3 to your computer and use it in GitHub Desktop.
Save craiggrella/a4c50dc68d78b9801ba3 to your computer and use it in GitHub Desktop.
Custom query to sort by category in genesis
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 ' ';
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment