Edit search results template in WordPress

I have created a page template with a nice layout using the lovely custom fields plugin so my client can easily update the content.

I created a loop on that page template that displays the relevant information nicely;

Read More

Here is the loop I made:

        <?php
    $args = array( 'post_type' => 'cripps_staff', 'posts_per_page' => 300 );
    $loop = new WP_Query( $args );
    while ( $loop->have_posts() ) : $loop->the_post();

    echo '<div class="col-md-3 spacetop">';
    echo '<a href="'.get_permalink().'">';
    echo get_post_meta($post->ID,'image',true);
    echo '</a>';
    echo '<h2 class="staffname">';
    echo get_post_meta($post->ID,'staff_name',true);
    echo '</h2>';
    echo '<h2 class="staffrole">';
    echo get_post_meta($post->ID,'staff_role',true);
    echo '</h2>';
    echo '<h2 class="staffnumber">';
    echo get_post_meta($post->ID,'staff_telephone_number',true);
    echo '</h2>';
    echo '<h2 class="staffemail">';
    echo get_post_meta($post->ID,'staff_email_address',true);
    echo '</h2>';
    echo '</div>';
    endwhile;
    ?>

I created taxonomies so the staff members are split into categories.

I am then using a plugin called Taxonomies filter to create those dropdown options you will see. When you select an element in the dropdowns, WordPress goes to/changes the page to a custom search results page I created. I want my search results to be displayed exactly like my loop on the People’s template. Currently it just spits it out the title in a h1 tag.

Here is the code I got from the Twenty Fourteen theme:

                <?php
                // Start the Loop.
                while ( have_posts() ) : the_post();

                    /*
                     * Include the post format-specific template for the content. If you want to
                     * use this in a child theme, then include a file called called content-___.php
                     * (where ___ is the post format) and that will be used instead.
                     */
                    get_template_part( 'content', get_post_format() );

                endwhile;
                // Previous/next post navigation.
                CrippsTheme_paging_nav();

            else :
                // If no content, include the "No posts found" template.
                get_template_part( 'content', 'none' );

            endif;
        ?>

How can I get the search results to look exactly like my Post loop?

Related posts

Leave a Reply

1 comment