Skip to content

Instantly share code, notes, and snippets.

@sareiodata
Last active August 29, 2015 13:59
Show Gist options
  • Select an option

  • Save sareiodata/10885367 to your computer and use it in GitHub Desktop.

Select an option

Save sareiodata/10885367 to your computer and use it in GitHub Desktop.
Profile Builder User Listing with user posts
<?php
//////////////////////////////////////////////////////////////////////////////////////////////////
// List user posts on the single user listing
//////////////////////////////////////////////////////////////////////////////////////////////////
add_shortcode( 'wppb-user-posts', 'wppb_custom_list_user_posts' );
function wppb_custom_list_user_posts(){
//get user ID
if (isset($_GET['userID'])){
$user_id = $_GET['userID'];
}else{
$user_id = get_query_var( 'username' );
}
$output = '';
if ( $user_id != '' ) {
$args = array(
'posts_per_page' => -1,
'author' => $user_id,
);
$posts_array = get_posts( $args );
if ( $posts_array != null ){
ob_start();
echo "<ul class='wppb-user-posts'>";
foreach ( $posts_array as $post ){
?>
<li><a href="<?php echo get_permalink( $post->ID )?>"><?php echo $post->post_title; ?></a></li>
<?php
$output = ob_get_contents();
ob_end_clean();
}
echo "</ul>";
} else {
ob_start();
echo '<p><strong>No posts</strong></p>';
$output = ob_get_contents();
ob_end_clean();
}
}
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment