I've been reading several different articles/posts to see if it could help me with my problem, but no luck so far. My goal is to make a custom search for a custom post type: restaurants. When I'm using the custom search I still get all posts from the site except the ones from my custom post type.
At the moment I'm using Filter & Search plugin to filter between custom categories for the custom post type, which works as it should. When I add search with or without the categories it does not - it simply can't find anything.
My custom post type in functions.php looks like this:
function custom_post_type() {
$labels = array(
'name' => _x( 'Restaurants', 'Post Type General Name', 'wp-bootstrap-starter-child' ),
'singular_name' => _x( 'Restaurant', 'Post Type Singular Name', 'wp-bootstrap-starter-child' ),
'menu_name' => __( 'Restaurants', 'wp-bootstrap-starter-child' ),
'parent_item_colon' => __( 'Parent Restaurant', 'wp-bootstrap-starter-child' ),
'all_items' => __( 'All Restaurants', 'wp-bootstrap-starter-child' ),
'view_item' => __( 'View Restaurant', 'wp-bootstrap-starter-child' ),
'add_new_item' => __( 'Add New Restaurant', 'wp-bootstrap-starter-child' ),
'add_new' => __( 'Add New', 'wp-bootstrap-starter-child' ),
'edit_item' => __( 'Edit Restaurant', 'wp-bootstrap-starter-child' ),
'update_item' => __( 'Update Restaurant', 'wp-bootstrap-starter-child' ),
'search_items' => __( 'Search Restaurant', 'wp-bootstrap-starter-child' ),
'not_found' => __( 'Not Found', 'wp-bootstrap-starter-child' ),
'not_found_in_trash' => __( 'Not found in Trash', 'wp-bootstrap-starter-child' ),
);
$args = array(
'label' => __( 'restaurants', 'wp-bootstrap-starter-child' ),
'description' => __( 'Restaurant news and reviews', 'wp-bootstrap-starter-child' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'thumbnail', 'revisions', 'custom-fields' ),
// You can associate this CPT with a taxonomy or custom taxonomy.
'taxonomies' => array( 'restaurant-category', 'restaurant-category-placering', 'restaurant-category-pris' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type( 'restaurants', $args );
} add_action( 'init', 'custom_post_type', 0 );
I've tried several diffent forms for the search submit, all with the
<input type="hidden" name="post_type" value="restaurants">
but it still only search regular posts.
I've a custom search.php aswell looking like this:
$args = array(
'post_type'=> 'restaurants',
's' => $s,
'paged' => $paged,
);
query_posts($args);
// Template Name: Search Results
$search_refer = $_GET["post_type"];
if ($search_refer == 'restaurants') { load_template(TEMPLATEPATH . '/search-restaurants.php'); }
else { custom HTML
At this point I'm thinking I'm missing a step, where I include the custom post type in search function or something like that.
PS.: when I type this www.example.com/?post_type=restaurants I'll get the custom archive - not sure if it is relevant.
Forgot to mention, that the site is currently using the theme 15Zine
Thanks in advance!