1 <?php
2 $args = array(
3 'post_type' => 'custom_type',
4 'post_status' => 'publish',
5 'posts_per_page' => 8,
6 'orderby' => 'title',
7 'order' => 'ASC',
8 );
9
10 $loop = new WP_Query( $args );
11
12 while ( $loop->have_posts() ) : $loop->the_post();
13 print the_title();
14 the_excerpt();
15 endwhile;
16
17 wp_reset_postdata();
18 ?>
1<?php
2$args = array(
3 'post_type' => 'product',
4 'posts_per_page' => 10,
5);
6$loop = new WP_Query($args);
7while ( $loop->have_posts() ) {
8 $loop->the_post();
9 ?>
10 <div class="entry-content">
11 <?php the_title(); ?>
12 <?php the_content(); ?>
13 </div>
14 <?php
15}
16
1/*
2* Creating a function to create our CPT
3*/
4
5function custom_post_type() {
6
7// Set UI labels for Custom Post Type
8 $labels = array(
9 'name' => _x( 'Movies', 'Post Type General Name', 'twentytwenty' ),
10 'singular_name' => _x( 'Movie', 'Post Type Singular Name', 'twentytwenty' ),
11 'menu_name' => __( 'Movies', 'twentytwenty' ),
12 'parent_item_colon' => __( 'Parent Movie', 'twentytwenty' ),
13 'all_items' => __( 'All Movies', 'twentytwenty' ),
14 'view_item' => __( 'View Movie', 'twentytwenty' ),
15 'add_new_item' => __( 'Add New Movie', 'twentytwenty' ),
16 'add_new' => __( 'Add New', 'twentytwenty' ),
17 'edit_item' => __( 'Edit Movie', 'twentytwenty' ),
18 'update_item' => __( 'Update Movie', 'twentytwenty' ),
19 'search_items' => __( 'Search Movie', 'twentytwenty' ),
20 'not_found' => __( 'Not Found', 'twentytwenty' ),
21 'not_found_in_trash' => __( 'Not found in Trash', 'twentytwenty' ),
22 );
23
24// Set other options for Custom Post Type
25
26 $args = array(
27 'label' => __( 'movies', 'twentytwenty' ),
28 'description' => __( 'Movie news and reviews', 'twentytwenty' ),
29 'labels' => $labels,
30 // Features this CPT supports in Post Editor
31 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
32 // You can associate this CPT with a taxonomy or custom taxonomy.
33 'taxonomies' => array( 'genres' ),
34 /* A hierarchical CPT is like Pages and can have
35 * Parent and child items. A non-hierarchical CPT
36 * is like Posts.
37 */
38 'hierarchical' => false,
39 'public' => true,
40 'show_ui' => true,
41 'show_in_menu' => true,
42 'show_in_nav_menus' => true,
43 'show_in_admin_bar' => true,
44 'menu_position' => 5,
45 'can_export' => true,
46 'has_archive' => true,
47 'exclude_from_search' => false,
48 'publicly_queryable' => true,
49 'capability_type' => 'post',
50 'show_in_rest' => true,
51
52 );
53
54 // Registering your Custom Post Type
55 register_post_type( 'movies', $args );
56
57}
58
59/* Hook into the 'init' action so that the function
60* Containing our post type registration is not
61* unnecessarily executed.
62*/
63
64add_action( 'init', 'custom_post_type', 0 );
1//WordPress: Query a custom post type
2//For example, query all Case Study post types
3
4<?php query_posts('post_type=case_studies'); ?>
1.wp-block-code {
2 border: 0;
3 padding: 0;
4}
5
6.wp-block-code > div {
7 overflow: auto;
8}
9
10.hljs {
11 box-sizing: border-box;
12}
13
14.hljs.shcb-code-table {
15 display: table;
16 width: 100%;
17}
18
19.hljs.shcb-code-table > .shcb-loc {
20 color: inherit;
21 display: table-row;
22 width: 100%;
23}
24
25.hljs.shcb-code-table .shcb-loc > span {
26 display: table-cell;
27}
28
29.wp-block-code code.hljs:not(.shcb-wrap-lines) {
30 white-space: pre;
31}
32
33.wp-block-code code.hljs.shcb-wrap-lines {
34 white-space: pre-wrap;
35}
36
37.hljs.shcb-line-numbers {
38 border-spacing: 0;
39 counter-reset: line;
40}
41
42.hljs.shcb-line-numbers > .shcb-loc {
43 counter-increment: line;
44}
45
46.hljs.shcb-line-numbers .shcb-loc > span {
47 padding-left: 0.75em;
48}
49
50.hljs.shcb-line-numbers .shcb-loc::before {
51 border-right: 1px solid #ddd;
52 content: counter(line);
53 display: table-cell;
54 padding: 0 0.75em;
55 text-align: right;
56 -webkit-user-select: none;
57 -moz-user-select: none;
58 -ms-user-select: none;
59 user-select: none;
60 white-space: nowrap;
61 width: 1%;
62}
63// Register Custom Post Type - Workshop
64function kp_workshops() {
65
66 $args = array(
67 'label' =>; __( 'Workshop', 'kp_workshops' ),
68 'description' =>; __( 'Workshop listing', 'kp_workshops' ),
69 'labels' =>; $labels,
70 'supports' =>; array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields' ),
71 'taxonomies' =>; array( 'category' ),
72 'hierarchical' =>; false,
73 'public' =>; true,
74 'show_ui' =>; true,
75 'show_in_menu' =>; true,
76 'menu_position' =>; 20,
77 'menu_icon' =>; 'dashicons-welcome-learn-more',
78 'show_in_admin_bar' =>; true,
79 'show_in_nav_menus' =>; true,
80 'can_export' =>; true,
81 'has_archive' =>; true,
82 'exclude_from_search' =>; false,
83 'publicly_queryable' =>; true,
84 'capability_type' =>; 'page',
85 'show_in_rest' =>; true,
86 );
87
88 register_post_type( 'workshops', $args );
89
90}
91add_action( 'init', 'kp_workshops', 0 );