Testimonial Post Type (Basic Structure)

PHOTO EMBED

Thu Jun 26 2025 19:20:15 GMT+0000 (Coordinated Universal Time)

Saved by @Muhammad_Waqar

function create_testimonial() {

    $labels = array(
        'name' => _x( 'Testimonial', 'Post Type General Name'),
        'singular_name' => _x( 'Testimonial', 'Post Type Singular Name'),
        'menu_name' => _x( 'Testimonial', 'Admin Menu text'),
        'name_admin_bar' => _x( 'Testimonial', 'Add New on Toolbar'),
        'archives' => __( 'Testimonial Archives'),
        'attributes' => __( 'Testimonial Attributes'),
        'parent_item_colon' => __( 'Parent Testimonial:'),
        'all_items' => __( 'All Testimonial'),
        'add_new_item' => __( 'Add New Testimonial'),
        'add_new' => __( 'Add New'),
        'new_item' => __( 'New Testimonial'),
        'edit_item' => __( 'Edit Testimonial'),
        'update_item' => __( 'Update Testimonial'),
        'view_item' => __( 'View Testimonial'),
        'view_items' => __( 'View Testimonial'),
        'search_items' => __( 'Search Testimonial'),
        'not_found' => __( 'Not found'),
        'not_found_in_trash' => __( 'Not found in Trash'),
        'featured_image' => __( 'Featured Image'),
        'set_featured_image' => __( 'Set featured image'),
        'remove_featured_image' => __( 'Remove featured image'),
        'use_featured_image' => __( 'Use as featured image'),
        'insert_into_item' => __( 'Insert into Testimonial'),
        'uploaded_to_this_item' => __( 'Uploaded to this Testimonial'),
        'items_list' => __( 'Testimonial list'),
        'items_list_navigation' => __( 'Testimonial list navigation'),
        'filter_items_list' => __( 'Filter Testimonial list'),
    );
    $rewrite = array(
        'slug' => 'testimonial',
        'with_front' => true,
        'pages' => true,
        'feeds' => true,
    );
    $args = array(
        'label' => __( 'Testimonial'),
        'description' => __( ''),
        'labels' => $labels,
        'menu_icon' => 'dashicons-admin-appearance',
        'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'page-attributes', 'post-formats'),
        'taxonomies' => array(),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 5,
        'show_in_admin_bar' => true,
        'show_in_nav_menus' => true,
        'can_export' => true,
        'has_archive' => true,
        'hierarchical' => true,
        'exclude_from_search' => true,
        'show_in_rest' => true,
        'publicly_queryable' => true,
        'capability_type' => 'post',
        'rewrite' => $rewrite,
    );
    register_post_type( 'testimonial', $args );
    
    }
    add_action( 'init', 'create_testimonial', 0 );
    
    function testimonial_loop(){
    ob_start();
    wp_reset_postdata();
    ?>
    
        <div id="slick-slides" class="owl-carousel services-sec">
    <?php 
        $arg = array(
            'post_type' => 'testimonial',
            'posts_per_page' =>-1, 
        );
    $testimonialPost = new WP_Query($arg);
    ?>
            <?php if ($testimonialPost->have_posts() ): ?>
                <?php while ($testimonialPost->have_posts() ) : ?>
                    <?php $testimonialPost->the_post(); ?>
                    
                        <div class="col-md-3 content">
                            <div class="testi_wrapper">
                                <div class="test_img">
                                    <?php the_post_thumbnail() ?>
                                </div>
                                <div class="test_content">
                                    <p><?php the_content() ?></p>
                                </div>
                                <div class="test_detail">
									<h4><?php the_title() ?></h4>
									<small><?php the_field('designation') ?></small>
                                </div>	
                            </div>
                        </div>
                    <?php endwhile; ?>
                <?php endif;?>
            </div>

    <?php
    wp_reset_postdata();
    return ''.ob_get_clean();
    }
    add_shortcode('testimonial_code', 'testimonial_loop');
content_copyCOPY