functions.php
require_once ('functions/city.php');
city.php
add_action( 'init', 'city_register');
function city_register() {
$labels = array(
'name' => _x('Cities', 'post type general name'),
'singular_name' => _x('City', 'post type singular name'),
'add_new' => _x('Add New', 'City'),
'add_new_item' => __('Add New City'),
'edit_item' => __('Edit City'),
'new_item' => __('New City'),
'all_items' => __('All Cities'),
'view_item' => __('View Cities'),
'search_items' => __('Search Cities'),
'not_found' => __('No cities found'),
'not_found_in_trash' => __('No cities found in Trash'),
'parent_item_colon' => '',
'menu_name' => 'Cities'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'),
'menu_icon' => 'dashicons-flag'
);
register_post_type('city', $args);
}
Developer Resources: Dashicons
template-city.php
<?php $args = array( 'posts_per_page' => -1, 'orderby' => 'menu_order', 'order'=>'ASC', 'post_type' => 'city'); query_posts($args); $lastposts = get_posts( $args ); ?> <?php foreach ( $lastposts as $post ) : $post_orig = $post; setup_postdata( $post ); ?> <div class="city"> <h3><?php the_title(); ?></h3> <div class="thumb"> <?php the_post_thumbnail(array(500, 500)); ?> </div> <?php the_content(); ?> </div> <?php endforeach; ?> <?php wp_reset_postdata();?> <?php wp_reset_query();?>
Hide backoffice Add, edit and delete buttons
function hide_feedback_stuff() {
if('feedback' == get_post_type())
echo '<style type="text/css">
.page-title-action, .wp-list-table thead tr th:first-of-type, .wp-list-table tfoot tr th:first-of-type, .wp-list-table tbody tr td:first-of-type {display:none;}
</style>';
}
add_action('admin_head', 'hide_feedback_stuff');
How to order posts of a custom post type by date DESC in dashboard Admin?
function wpse_819391_post_types_admin_order( $wp_query ) {
if ( is_admin() && !isset( $_GET['orderby'] ) ) {
$post_type = $wp_query->query['post_type'];
if ( in_array( $post_type, array('feedback','feedback2') ) ) {
$wp_query->set('orderby', 'date');
$wp_query->set('order', 'DESC');
}
}
}
add_filter('pre_get_posts', 'wpse_819391_post_types_admin_order');