【问题标题】:WordPress: Creating a search form for custom post typesWordPress:为自定义帖子类型创建搜索表单
【发布时间】:2011-03-18 04:43:00
【问题描述】:

如果我想构建一个搜索自定义帖子类型的表单,即完全重建的表单,我应该注意什么?创建实际的表单及其元素没有问题,但接下来的步骤会带来很多棘手的问题,例如,

  1. 如何将$_GET 数据传递到另一个文件,以保持 WordPress 的永久链接完好无损?

  2. 如何处理帖子,而无需创建 if 语句金字塔,而是使用 WordPress 自己的核心功能?

【问题讨论】:

    标签: wordpress search custom-post-type


    【解决方案1】:

    尝试查看下面的代码并将您的版本放入 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));
    

    【讨论】:

      猜你喜欢
      • 2015-11-06
      • 1970-01-01
      • 2016-05-13
      • 2012-09-14
      • 1970-01-01
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多