• Hello,

    I am trying to set up a page on my website that lists all of my testimonials. They are set up as a custom post type named, “testimonials.” I created a custom page template by renaming my page.php template. Can anyone help me figure out what the code is to query my custom post type “testimonials” and where it belong in my testimonials_page.php template (code below)? I would like to show all of my testimonial posts with pagination.

    I’ve been trying to figure this out for two weeks with no success and I really appreciate any help possible.

    <?php
    /*
    Template Name: Client Testimonials

    */
    ?>

    <?php get_header(); ?>

    <div id=”container”>

    <div id=”main”>

    Throughout the years, my clients have generously provided the following 100% unedited testimonials. If you would like to submit a testimonial, please complete the form on the right side of this page.

    <div class=rule></div>

    query_posts ( ‘post_type’ = ‘testimonials’);

    <?php if ( have_posts() ): ?>

    <?php while ( have_posts() ): ?>

    <?php the_post(); ?>

    <div id=”post-<?php the_ID(); ?>” <?php // post_class(); ?>>

    <?php if ( is_front_page() ) : ?>

    <?php $queried_object = $wp_query->get_queried_object(); ?>

    <?php $subtitle = get_post_meta($queried_object->ID, ‘subtitle’); ?>

    <?php $title = the_title( ”, ”, false ); ?>

    <?php endif; ?>

    <div class=”entry-content”>

    <?php the_content(); ?>

    <?php wp_link_pages( array( ‘before’ => ‘<div class=”page-link”>’ . __( ‘Pages:’, ‘simplicius’ ), ‘after’ => ‘</div>’ ) ); ?>

    <!– <?php edit_post_link( __( ‘Edit’, ‘simplicius’ ), ‘<span class=”edit-link”>’, ‘</span>’ ); ?> –>

    </div><!– .entry-content –>

    </div><!– #post-## –>

    <?php endwhile; ?>

    <?php endif; ?>

    </div><!– /#content –>

    </div><!– /#container –>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

Viewing 7 replies - 1 through 7 (of 7 total)
  • Untested Example:

    <?php
    	$wp_query= null;
    	$wp_query = new WP_Query();
    	$args = array(
    		'post_type' => 'testimonials',
    		'showposts' => '10',
    		'&paged' => $paged,
    	);
    	$wp_query->query( $args );
    ?>
    
    <?php if ( $wp_query->have_posts() ) : ?>
    
    	<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
    
    		<!-- Output testimonial here -->
    
    	<?php endwhile; ?>
    
    <?php endif; ?>

    HTH

    David

    Thread Starter alicatgatorgirl

    (@alicatgatorgirl)

    https://photographybyericah.com/wordpress/about/client-testimonials/

    Can you check my code below and see if you think I put the code in the wrong place?

    <?php
    /*
    Template Name: Client Testimonials

    */
    ?>

    <?php get_header(); ?>

    <div id=”container”>

    <div id=”main”>

    Throughout the years, my clients have generously provided the following 100% unedited testimonials. If you would like to submit a testimonial, please complete the form on the right side of this page.

    <div class=rule></div>

    query_posts ( ‘post_type’ = ‘testimonials’);

    <?php
    $wp_query= null;
    $wp_query = new WP_Query();
    $args = array(
    ‘post_type’ => ‘testimonials’,
    ‘showposts’ => ’10’,
    ‘&paged’ => $paged,
    );
    $wp_query->query( $args );
    ?>

    <?php if ( $wp_query->have_posts() ) : ?>

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

    <!– Output testimonial here –>

    <?php endwhile; ?>

    <?php endif; ?>
    </div><!– /#content –>

    </div><!– /#container –>

    <?php get_sidebar(); ?>

    <?php get_footer(); ?>

    Thanks again!

    Thread Starter alicatgatorgirl

    (@alicatgatorgirl)

    I forgot to mention that when I put that code in, my sidebar testimonials form disappeared. So, I changed my page template back to its original to get the form back.

    Hi Alicatgatorgirl,
    Can you post the contents of page.php and not your template to https://pastebin.com

    Then paste the pastebin page link back down here, we are meant to use pastebin for large code blocks.

    Cheers

    David

    Thread Starter alicatgatorgirl

    (@alicatgatorgirl)

    Hi David,

    Sorry about that. I’m new to this and its the first time I have had to paste large code. My page.php file contents are located at

    https://pastebin.com/s7FtkwuC

    Thanks again!

    This is tested code.
    https://pastebin.com/t1b1VMds

    The pagination you will need to add as pages do not have pagination.

    You should find the pagination code in index.php, loop.php or content.php, and you can adjust how many show with 'showposts' => '10',

    In the linked code you will see:

    <!-- Add Top Pagination Code Here -->
    <!-- Add Bottom Pagination Code Here -->

    Replace these lines with your pagination code.

    Note:
    I have not hard coded the text, the template will allow you to add the the text, just create a page and add your page content as normal, then apply the template.

    Throughout the years, my clients have generously provided the following 100% unedited testimonials. If you would like to submit a testimonial, please complete the form on the right side of this page.

    If this resolves this topic, please mark it as Resolved

    HTH

    David

    Thread Starter alicatgatorgirl

    (@alicatgatorgirl)

    Hi David,

    Thanks for your help. My custom post type was set up as part of the “Testimonials for WordPress” plugin that I purchased. The code isn’t working, but since it was tested, it must be a problem with my plugin working with the code…as it just deletes my existing page content (sidebar) when I upload the tested code. I have emailed the plugin developer to see if he can provide any input. I’ll mark it as resolved if I can get it working! Thanks again ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Query Custom Post Type Help’ is closed to new replies.