【发布时间】:2011-03-18 04:43:00
【问题描述】:
如果我想构建一个搜索自定义帖子类型的表单,即完全重建的表单,我应该注意什么?创建实际的表单及其元素没有问题,但接下来的步骤会带来很多棘手的问题,例如,
如何将
$_GET数据传递到另一个文件,以保持 WordPress 的永久链接完好无损?如何处理帖子,而无需创建 if 语句金字塔,而是使用 WordPress 自己的核心功能?
【问题讨论】:
标签: wordpress search custom-post-type
如果我想构建一个搜索自定义帖子类型的表单,即完全重建的表单,我应该注意什么?创建实际的表单及其元素没有问题,但接下来的步骤会带来很多棘手的问题,例如,
如何将$_GET 数据传递到另一个文件,以保持 WordPress 的永久链接完好无损?
如何处理帖子,而无需创建 if 语句金字塔,而是使用 WordPress 自己的核心功能?
【问题讨论】:
标签: wordpress search custom-post-type
尝试查看下面的代码并将您的版本放入 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));
【讨论】: