• I have added Testimonials Tab in Backend Admin Panel Tab. I can add new Testimonials there. Testimonials are Working perfect in Admin Panel. Saving all..
    But i am unable to show on Front page. I want to show on Index page..
    Here are my codes which i have added into “Functions.php”

    add_action( 'init', 'testimonials_post_type' );
    function testimonials_post_type() {
        $labels = array(
            'name' => 'Testimonials',
            'singular_name' => 'Testimonial',
            'add_new' => 'Add New',
            'add_new_item' => 'Add New Testimonial',
            'edit_item' => 'Edit Testimonial',
            'new_item' => 'New Testimonial',
            'view_item' => 'View Testimonial',
            'search_items' => 'Search Testimonials',
            'not_found' =>  'No Testimonials found',
            'not_found_in_trash' => 'No Testimonials in the trash',
            'parent_item_colon' => '',
        );
    
        register_post_type( 'testimonials', array(
            'labels' => $labels,
            'public' => true,
            'publicly_queryable' => true,
            'show_ui' => true,
            'exclude_from_search' => true,
            'query_var' => true,
            'rewrite' => true,
            'capability_type' => 'post',
            'has_archive' => true,
            'hierarchical' => false,
            'menu_position' => 10,
            'supports' => array( 'editor' ),
            'register_meta_box_cb' => 'testimonials_meta_boxes', // Callback function for custom metaboxes
        ) );
    }
    function testimonials_meta_boxes() {
        add_meta_box( 'testimonials_form', 'Testimonial Details', 'testimonials_form', 'testimonials', 'normal', 'high' );
    }
    
    function testimonials_form() {
        $post_id = get_the_ID();
        $testimonial_data = get_post_meta( $post_id, '_testimonial', true );
        $client_name = ( empty( $testimonial_data['client_name'] ) ) ? '' : $testimonial_data['client_name'];
        $source = ( empty( $testimonial_data['source'] ) ) ? '' : $testimonial_data['source'];
        $link = ( empty( $testimonial_data['link'] ) ) ? '' : $testimonial_data['link'];
    
        wp_nonce_field( 'testimonials', 'testimonials' );
        ?>
        <p>
            <label>Client's Name (optional)</label><br />
            <input type="text" value="<?php echo $client_name; ?>" name="testimonial[client_name]" size="40" />
        </p>
        <p>
            <label>Business/Site Name (optional)</label><br />
            <input type="text" value="<?php echo $source; ?>" name="testimonial[source]" size="40" />
        </p>
        <p>
            <label>Link (optional)</label><br />
            <input type="text" value="<?php echo $link; ?>" name="testimonial[link]" size="40" />
        </p>
        <?php
    }
    add_action( 'save_post', 'testimonials_save_post' );
    function testimonials_save_post( $post_id ) {
        if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
            return;
    
        if ( ! empty( $_POST['testimonials'] ) && ! wp_verify_nonce( $_POST['testimonials'], 'testimonials' ) )
            return;
    
        if ( ! empty( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) {
            if ( ! current_user_can( 'edit_page', $post_id ) )
                return;
        } else {
            if ( ! current_user_can( 'edit_post', $post_id ) )
                return;
        }
    
        if ( ! wp_is_post_revision( $post_id ) && 'testimonials' == get_post_type( $post_id ) ) {
            remove_action( 'save_post', 'testimonials_save_post' );
    
            wp_update_post( array(
                'ID' => $post_id,
                'post_title' => 'Testimonial - ' . $post_id
            ) );
    
            add_action( 'save_post', 'testimonials_save_post' );
        }
    
        if ( ! empty( $_POST['testimonial'] ) ) {
            $testimonial_data['client_name'] = ( empty( $_POST['testimonial']['client_name'] ) ) ? '' : sanitize_text_field( $_POST['testimonial']['client_name'] );
            $testimonial_data['source'] = ( empty( $_POST['testimonial']['source'] ) ) ? '' : sanitize_text_field( $_POST['testimonial']['source'] );
            $testimonial_data['link'] = ( empty( $_POST['testimonial']['link'] ) ) ? '' : esc_url( $_POST['testimonial']['link'] );
    
            update_post_meta( $post_id, '_testimonial', $testimonial_data );
        } else {
            delete_post_meta( $post_id, '_testimonial' );
        }
    }
    add_filter( 'manage_edit-testimonials_columns', 'testimonials_edit_columns' );
    function testimonials_edit_columns( $columns ) {
        $columns = array(
            'cb' => '<input type="checkbox" />',
            'title' => 'Title',
            'testimonial' => 'Testimonial',
            'testimonial-client-name' => 'Client\'s Name',
            'testimonial-source' => 'Business/Site',
            'testimonial-link' => 'Link',
            'author' => 'Posted by',
            'date' => 'Date'
        );
    
        return $columns;
    }
    
    add_action( 'manage_posts_custom_column', 'testimonials_columns', 10, 2 );
    function testimonials_columns( $column, $post_id ) {
        $testimonial_data = get_post_meta( $post_id, '_testimonial', true );
        switch ( $column ) {
            case 'testimonial':
                the_excerpt();
                break;
            case 'testimonial-client-name':
                if ( ! empty( $testimonial_data['client_name'] ) )
                    echo $testimonial_data['client_name'];
                break;
            case 'testimonial-source':
                if ( ! empty( $testimonial_data['source'] ) )
                    echo $testimonial_data['source'];
                break;
            case 'testimonial-link':
                if ( ! empty( $testimonial_data['link'] ) )
                    echo $testimonial_data['link'];
                break;
        }
    }

    Please tell me How i can show Only Text and Client Name on index page.. I want to use as Carousel Slider.. HTML is already done.
    I made a tweak into it but it shows only Posts of WordPress which i have added. Not Testimonials.. i want testimonials… Please Help

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘I have added "Testimonials" Tab in Admin Panel But not able to show Testimonials’ is closed to new replies.