2010-07-20 119 views
1

如果我想構建一個可以搜索自定義帖子類型(即完全重建的表單)的表單,應該查看哪些內容?創建的形式和它的內容是沒有問題的,但在接下來的步驟帶來了很多棘手的問題,例如,WordPress:爲自定義帖子類型創建搜索表單

  1. 如何我可以通過$_GET數據到另一個文件維護的WordPress的永久鏈接完好?

  2. 如何處理帖子而不必創建if語句金字塔,而是使用WordPress自己的核心功能?

回答

0

試着看下面的代碼,並把它的版本放在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)); 
相關問題