• I have a search function on my WordPress site, and I’ve only just noticed that it doesn’t seem to include my custom post-type’s tags in the search. It is absolutely essential that my search includes tags when searching, so I wondered whether there is a simple solution here? I have looked on the net but can’t seem to find a solution anywhere!

    Here’s my html:

    <ul>
        <?php if ( have_posts() ) : ?>
        <?php while ( have_posts() ) : the_post(); ?>
        <li class="resultItem">
            <?php if (has_post_thumbnail( $post->ID )): ?>
                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); ?>
                <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/thumbs.php?src=<?php echo $image[0]; ?>&w=120&h=120&zc=1" alt="<?php the_title(); ?>" /></a>
            <?php endif; ?>
            <div id="resultText">
                <h2 class="redSubHeader"><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
                <?php the_excerpt(); ?>
            </div>
        </li>
        <?php endwhile;?>
    </ul>

    And here’s the php which makes my search only search within the ‘event’ custom post-type:

    // Only search for Events post-type in keyword search
    
    function SearchFilter($query) {
    if ($query->is_search) {
    $query->set('post_type', 'events');
    }
    return $query;
    }
    
    add_filter('pre_get_posts','SearchFilter');

    Thanks guys ??

  • The topic ‘Include tags in my search’ is closed to new replies.