Add extra columns in WordPress admin custom post types

add_filter( ‘manage_{custom_post_type}_posts_columns’, ‘set_custom_post_type_edit_columns’ );
function set_custom_post_type_edit_columns($columns){
$columns[‘user_mail’] = __( ‘Email’, ‘your_text_domain’ );
return $columns;
}
add_action( ‘manage_{custom_post_type}_posts_custom_column’ , ‘custom_post_type_column’, 10, 2 );
function custom_post_type_column( $column, $post_id ) {
switch ( $column ) {
case ‘user_mail’ :
echo get_post_meta( $post_id , ‘user_mail’ , true );
break;
}
}

Advertisements

Custom post type list with pagination in while loop

<?php

$loop = new WP_Query(array(‘post_type’ => ‘custom_post’,  ‘posts_per_page’ => 5,  ‘paged’ => get_query_var(‘paged’) ? get_query_var(‘paged’) : 1 ));

?>

<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>

<?php the_title(); ?> <?php the_content(); ?>

<?php endwhile; ?>

<?php  $uniqnum = 999999999;

echo paginate_links( array( ‘base’ => str_replace( $uniqnum, ‘%#%’, get_pagenum_link( $uniqnum ) ),

‘format’ => ‘?paged=%#%’,

‘current’ => max( 1, get_query_var(‘paged’) ),

‘total’ => $loop->max_num_pages ) );

?>