我一直在阅读几篇不同的文章/帖子,看看它是否能帮助我解决问题,但目前为止我运气不好。我的目标是对自定义帖子类型进行自定义搜索:restaurants. 当我使用自定义搜索时,我仍然会从该站点获取所有帖子,但自定义帖子类型中的帖子除外。
目前,我正在使用过滤器&;搜索插件以在自定义类别之间过滤自定义帖子类型,这是它应该做的。当我添加带有或不带类别的搜索时,它不会-它根本找不到任何东西。
我的自定义帖子输入函数。php如下所示:
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 );
}添加操作(\'init\',\'custom\\u post\\u type\',0);
我尝试了几种不同的搜索提交表单,所有表单都带有<input type="hidden" name="post_type" value="restaurants">
但它仍然只搜索常规帖子。
我有一个自定义搜索。php也是这样:
$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
此时,我想我错过了一个步骤,在搜索功能中包含自定义帖子类型或类似的内容。
注:当我键入这个www.example时。com/?post\\u type=餐厅我将获取自定义存档-不确定是否相关。
忘了提一下,该网站目前正在使用主题15Zine
提前感谢!