如何通过帖子标题和剩余的帖子匹配后搜索帖子?

时间:2016-10-20 07:50:15

标签: php wordpress search

我希望通过帖子标题完全匹配搜索帖子,并在帖子内容或类似匹配后匹配,例如我想搜索"怀孕"答案应该是第一次完全匹配后标题和赛后标题,如#34;怀孕"或从帖子内容中搜索。以下是我的搜索代码,请指导我。

<?php
$args = array (
    's' => $s,
    'category__in' => $category,
    'year' => $year,
    'monthnum' => $monthnum,
    'paged' => $paged,
    'order' => $sortby,
    'tax_query' => $filterq,
    'post_status' => 'publish',
    'orderby'   => 'title',
);


$query = new WP_Query($args) ;
// print_r($query);
if ( $query->have_posts() ) :
    echo '<ul>';
    while ( $query->have_posts() ) : $query->the_post();
        if(mom_option('search_page_ex') == true) {                                    
            if (is_type_page()) {
                continue;
            }
        }
?>
<li <?php post_class(); ?> itemscope="" itemtype="http://schema.org/Article">
    <?php if (mom_post_image() != false) { ?>
    <figure class="post-thumbnail"><a href="<?php the_permalink(); ?>">
        <?php mom_post_image_full('search-grid'); ?>
        <span class="post-format-icon"></span>
    </a></figure>
    <?php } ?>
    <?php if( mom_post_image() != false ) { 
        $mom_class = ' class="fix-right-content"';    
    } else {
        $mom_class = '';
    }
    ?>
    <div<?php echo $mom_class; ?>>
    <h2 itemprop="name"><a itemprop="url" href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
    <div class="entry-content">
        <p>
            <?php global $post;
            $excerpt = $post->post_excerpt;
            if($excerpt==''){
            $excerpt = get_the_content('');
            }
            echo wp_html_excerpt(strip_shortcodes($excerpt), 115);
            ?> ...
        </p>
    </div>
    <?php if($post_head != 0) { ?>
    <div class="entry-meta">
    <?php if($post_head_date != 0) { ?>
        <time class="entry-date" datetime="<?php the_time('c'); ?>" itemprop="dateCreated"><i class="momizat-icon-calendar"></i><?php echo mom_date_format(); ?></time>
        <?php } ?>
        <?php if($post_head_commetns != 0) { ?>
        <div class="comments-link">
            <i class="momizat-icon-bubbles4"></i><a href="<?php comments_link(); ?>"><?php comments_number(__( '(0) Comments', 'framework' ), __( '(1) Comment', 'framework' ),__( '(%) Comments', 'framework' )); ?></a>
        </div>
        <?php } ?>
    </div>
    <?php } ?>
    </div>
</li>
<?php endwhile;
echo '</ul>'; ?>

0 个答案:

没有答案