首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >wordpress搜索结果页

问wordpress搜索结果页
EN

Stack Overflow用户
提问于 2016-09-03 17:07:34
回答 1查看 166关注 0票数 0

我的搜索页面结果有问题。我已经创建了搜索主题。当我搜索已经在我的数据库中的单词'موفقیت‘时,它会返回所有的结果,并且工作正常,但我只想搜索特殊的自定义post类型,而不是所有的post和pages.how,我能解决这个问题吗

以下是我的代码

代码语言:javascript
复制
    <?php 
 get_header(); ?>
<div class="title-pack col-md-12 col-sm-12 col-xs-12">
        <span class="line visible-sm-block"></span>
        <span class="visible-sm-block tittle-style">نتایج جستجوی شما</span>
    </div>
<div id="search-results" class="wrapper" role="search">


<!-- COUNT RESULTS -->
<div class="results">
    <?php
    /* Search Count */
    $allsearch = &new WP_Query("s=$s&showposts=-1"); 
    $key = wp_specialchars($s, 1);
    $count = $allsearch->post_count; 
    _e('');
    _e('"<span class="search-terms">');
    echo $key;
    _e('</span>"'); 
    echo $count . ' مورد یافت شد';
    wp_reset_query(); ?>

</div>
<!-- / COUNT RESULTS -->

<?php if ($allsearch->have_posts()) : ?>
<?php while ($allsearch->have_posts()) : $allsearch->the_post(); ?>

<!-- LIST RESULTS -->
<section>   
    <h3>
        <li>
        <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to 
        <?php the_title_attribute(); ?>"><?php the_title(); ?></a> - 
        <span class="search-time"><?php the_time('F, j, Y') ?></span>
        </li>
    </h3>
</section>
<!-- / LIST RESULTS -->

<?php endwhile; else: ?>

<!-- 404 SEARCH -->
<div class="404-search">
<?php _e("Oops... We couldn't find what you were searching for. Please try again"); ?>
</div>
<!-- / 404 SEARCH -->

<?php endif; ?>

     </div>


 <div style="clear:both;"></div>            
 <?php get_footer(); ?> 


     <div style="clear:both;"></div>            
     <?php get_footer(); ?> 

任何想法都会被盗用。

EN

回答 1

Stack Overflow用户

发布于 2016-09-03 17:24:40

尝尝这个,

代码语言:javascript
复制
$search_query['post_status'] = 'publish';
$search_query['post_type'] = 'book'; //your custom post type
// Custom query.
$search = new WP_Query($search_query);

// Check that we have query results.
if ( $search->have_posts() ) {

    // Start looping over the query results.
    while ( $search->have_posts() ) {

        $search->the_post();

        // Contents of the queried post results go here.

    }

}

// Restore original post data.
wp_reset_postdata();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39305191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档