WordPress:为自定义帖子类型创建搜索表单
问题描述:
如果我想构建一个可以搜索自定义帖子类型(即完全重建的表单)的表单,应该查看哪些内容?创建的形式和它的内容是没有问题的,但在接下来的步骤带来了很多棘手的问题,例如,WordPress:为自定义帖子类型创建搜索表单
如何我可以通过
$_GET
数据到另一个文件维护的WordPress的永久链接完好?如何处理帖子而不必创建if语句金字塔,而是使用WordPress自己的核心功能?
答
试着看下面的代码,并把它的版本放在functions.php文件中。这应该完美。你可能不得不用'和'替换'撇号'。
add_action(‘init’, ‘product_register’);
function product_register() {
$args = array(‘label’ => __(‘Products’), ‘singular_label’ => __(‘Product’), ‘public’ => true, ‘show_ui’ => true, ‘capability_type’ => ‘post’, ‘hierarchical’ => false, ‘rewrite’ => true, ‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’));
register_post_type(‘product’, $args);
}
add_action(“admin_init”, “admin_init”);
add_action(‘save_post’, ‘save_price’);
function admin_init() {
add_meta_box(“prodInfo - meta”, “Product Options”, “meta_options”, “product”, “side”, “low”);
}
function meta_options() {
global $post;
$custom = get_post_custom($post - > ID);
$price = $custom["price"][0];
echo‘ <label> Price: < /label><input type=”text” name=”price” value=”‘. $price .’”/> ’;
}
function save_price() {
global $post;
update_post_meta($post - > ID, “price”, $_POST["price"]);
}
// custom table columns
register_taxonomy(“catalog”, array(“product”), array(“hierarchical” => true, “label” => “Catalogs”, “singular_label” => “Catalog”, “rewrite” => true));