Reputation: 1
I'm trying to get custom post types and advanced custom fields to show in my search results. At the moment it only searches the default posts.
I have created my custom post types with this plugin: Custom Post Type UI
I'm using advanced custom field plugin: Advanced Custom Fields
Here is my code:
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(); ?>
Does anybody know how to fix this problem?
Best regards,
Johanna
Upvotes: 0
Views: 2499
Reputation: 3949
Put these when you define your custom post type
'query_var' => true,
'exclude_from_search' => false,
I think Custom Post type ui have the option.
Upvotes: 0