我正在尝试获取自定义帖子类型和高级自定义字段以显示在我的搜索结果中。目前它只搜索默认帖子。
我使用此插件创建了自定义帖子类型:Custom Post Type UI
我正在使用高级自定义字段插件:Advanced Custom Fields
这是我的代码:
的search.php
<?php get_header(); ?>
<div class="hakusanalla">
<h1 class="page-title"><?php printf( __( 'Tulokset haulle: %s', 'nothing' ), '' . get_search_query() . '' ); ?></h1>
</div>
<ul id="post-list">
<?php if ( have_posts() ) : while (have_posts()) : the_post(); ?>
<?php
$featured = get_post_meta($post->ID,'_thumbnail_id',true);
$attachments = get_children( 'post_type=attachment&orderby=menu_order&exclude='.$featured.'&post_mime_type=image&post_parent='.$post->ID );
$vimeo = get_post_meta($post->ID, 'rw_post-vimeo',true);
?>
<div class="hakutulos">
<li class="post">
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
<span class="entry-published">
<div class="hakudate">
<time datetime="<?php the_time('Y-m-d')?>"><?php the_time('F jS, Y') ?></time>
</div>
<?php the_excerpt(__('(more…)')); ?>
<?php get_template_part( 'includes/inc-image' ); ?>
<p><?php get_template_part( 'includes/inc-detail' ); ?></p>
</li>
</div>
<?php endwhile; ?>
</ul>
<section id="pagination">
<?php wp_pagenavi(); ?>
</section>
<?php else : ?>
<div class="errorlaatikko">
<h1><?php _e( 'Ei tuloksia', 'blankslate' ); ?></h1>
<p><?php _e( 'Hakemaasi sivua ei löytynyt. Tarkista oikeinkirjoitus tai kokeile hakua.', 'twentyten' ); ?></p>
<div class="errorhaku">
<?php get_search_form(); ?>
</div>
</div>
<?php endif; ?>
<?php get_footer(); ?>
searchform.php
<?php $search_text = "haku"; ?>
<form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
<input type="text" value="<?php echo $search_text; ?>"
name="s" id="search-form"
onblur="javascript: if( this.value != 'search') { this.value = 'search'; this.style.color = '#fff'; }"
onclick="javascript: if( this.value == 'search') { this.value = ''; this.style.color = '#fff'; }"
)
{this.value = '';}" />
<input placeholder="Etsi" type="submit" id="searchsubmit"/>
</form>
searchpage.php
<?php
/**
* Template Name: Search Page
*/
?>
<?php get_header(); ?>
<?php
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
$search = new WP_Query($search_query);
?>
<?php get_footer(); ?>
有人知道如何解决这个问题吗?
致以最诚挚的问候,
约翰娜
答案 0 :(得分:0)
在定义自定义帖子类型
时放置这些内容'query_var' => true,
'exclude_from_search' => false,
我认为Custom Post类型ui可以选择。