content-search.php duplicating the output for a certain post type

Question

So some odd reason my results page is fine with my custom post types, but for the default post type, it is duplicating/closing the <a> and creating the below output.
The output should only be 1 <a> element wrapped around the content. On the same search results page, the other content types are all fine.

Unexpected output:

<article id="post-956">
    <a class="box test box-hover bg-orange" href="https://www.example.com/post1">
    </a>
    <div class="container-fluid">
        <a class="box test box-hover bg-orange" href="https://www.example.com/post1">
        </a>
        <div class="row no-gutters"><a class="box test box-hover bg-orange" href="https://www.example.com/post1">
                <div class="col-3">
                </div>
            </a>
            <div class="col-9">
                <a class="box test box-hover bg-orange" href="https://www.example.com/post1">
                    <div class="post-type">Post</div>
                    <h2 class="result-title">Example Title</h2>
                    <h4 class="result-subtitle"> </h4>
                </a>
                <div class="entry-meta">
                    <a class="box test box-hover bg-orange" href="https://www.example.com/post1">
                        <span class="posted-on">Posted on </span>
                    </a>
                    <a href="https://www.example.com/post1" rel="bookmark">
                        <time class="entry-date published" datetime="2020-06-24T11:33:29+00:00">24th June 2020</time>
                    </a>
                </div>

                <section class="entry-summary">
                    <p>Content Excert Here</p>
                </section>
            </div>
        </div>
    </div>

</article>

This is the content of the search.php

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

        /**
         * Run the loop for the search to output the results.
         * If you want to overload this in a child theme then include a file
         * called content-search.php and that will be used instead.
         */
        get_template_part('template-parts/content', 'search');

    endwhile; ?>

This is the content-search.php

<?php if ($wp_query->current_post % 2 == 0) :
    $bgclass = 'bg-orange';
else :
    $bgclass = 'bg-grey';
endif 
?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> data-aos="flip-up">
    <a class="box box-hover <?php echo $bgclass; ?>" href="<?php the_permalink(); ?>">
        <div class="container-fluid container-no-padding">
            <div class="row no-gutters">
                <div class="col-3">
                    <?php
                    $image = get_field('case_study_logo');
                    $size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
                    if ($image) {
                        echo wp_get_attachment_image($image, $size);
                    } ?>

                    <?php
                    $image = get_field('featured_item');
                    $size = 'thumbnail'; // (thumbnail, medium, large, full or custom size)
                    if ($image) {
                        echo wp_get_attachment_image($image, $size);
                    } ?>
                </div>
                <div class="col-9">
                    <div class="post-type">
                        <?php $postType = get_post_type_object(get_post_type());
                        if ($postType) {
                            echo esc_html($postType->labels->singular_name);
                        } ?>
                    </div>

                    <h2 class="result-title"><?php the_title(); ?></h2>

                    <h4 class="result-subtitle"><?php the_field('sub_title'); ?>
                        <?php the_field('case_study_sub_title'); ?></h4>


                    <?php if ('post' === get_post_type()) : ?>
                        <div class="entry-meta">
                            <?php
                            example_posted_on();
                            example_posted_by();
                            ?>
                        </div><!-- .entry-meta -->
                    <?php endif; ?>

                    <section class="entry-summary">
                        <?php the_excerpt(); ?>
                    </section><!-- .entry-summary -->
                </div>
            </div>
        </div>
    </a>
</article><!-- #post-<?php the_ID(); ?> -->
0
iamonstage 2 months 0 Answers 12 views 0

Leave an answer