Removing date from pages not posts in search results (WordPress)

I’m trying to remove the date from pages only in search results.

I found this: https://wordpress.org/support/topic/search-results-hide-date-for-pages-not-posts – however, I can’t seem to figure out where to add it without causing errors.

Read More

I also found an answer suggesting just removing the date code from page.php but I don’t have that in there anyway.

My search.php:

<?php get_header(); ?>     
<?php get_sidebar(); ?>     
<div id="content">    
<div class="article">
<?php
$wp_query->query_vars["posts_per_page"] = 16;
$wp_query->get_posts();
?> 
 <?php if ( have_posts() ) : ?>
                <?php
                global $wp_query;
                $total_results = $wp_query->found_posts;
                ?>
                <?php printf( __( 'Search results for: %s', 'shape' ), '<span>' . get_search_query() . '</span>' ); ?>
                <br/><br/>
                <?php /* Start the Loop */ ?>
                <?php while ( have_posts() ) : the_post(); ?>
                <div class="searchresultsdate">
          <?php the_time('M j, Y') ?>        </div><div class="searchresults"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></div>
                           <?php endwhile; ?> 

</div>
<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } 

else { ?>

<div class="right"><?php next_posts_link('Next Page &raquo;') ?></div>

<div class="left"><?php previous_posts_link('&laquo; Previous Page') ?></div>

<?php } ?>
<br><br><br>    
<?php else : ?>   

<div class="posttitle">Nothing found. Try something else?</div>

This page doesn't exist

<?php endif; ?>    

<?php get_footer(); ?>

Related posts

1 comment

  1. Change

    <div class="searchresultsdate">
              <?php the_time('M j, Y') ?>        
    </div>
    

    to

    <?php  if ("page" != get_post_type()){ ?>
            <div class="searchresultsdate">
                  <?php the_time('M j, Y'); ?>        
            </div>
    <?php   } ?>
    

    Also you’re missing ‘;’ in many places.

Comments are closed.