你的 HTML 应该是这样的
<form role="search" method="get" id="searchform-conferences" action="">
<input type="text" name="search" value="Enter keywords ..." onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/><br />
<input type="hidden" name="post_type" value="posttypeconference" />
<input type="submit" id="searchsubmit" value="Search" />
</form>
你的 PHP 可能是这样的
<?php
$args = array( 'post_type' => $_POST['post_type'], 'posts_per_page' => 10, 'post_title' => 'LIKE %'.$_POST['search'].'%' );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
?>
您在哪里注册自定义帖子,请确保它类似于:
add_action('init', 'usb_init');
function usb_init()
{
$labels = array(
'name' => _x('USB', 'post type general name'),
'singular_name' => _x('USB', 'post type singular name'),
'add_new' => _x('Add New', 'usb'),
'add_new_item' => __('Add New USB'),
'edit_item' => __('Edit USB'),
'new_item' => __('New USB'),
'view_item' => __('View USB'),
'search_items' => __('Search USBs'),
'not_found' => __('No usb found'),
'not_found_in_trash' => __('No usb found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'product','with_front' => FALSE),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => '5',
'supports' => array('title','excerpt','editor','thumbnail','page-attributes'),
'taxonomies' => false
);
register_post_type('usb',$args);
}
'public' => true,'publicly_queryable' => true,'query_var' => true,
如果这仍然不起作用,您可以尝试添加:flush_rewrite_rules();
在您注册自定义帖子后