我已经注册了一个自定义帖子类型,确保“支持”中有“评论”,并且允许在“设置”->“讨论”下的新帖子上发表评论。
我确实看到了允许评论和允许回溯/ping的复选框。如果我选中“允许评论”,则更新/发布帖子,it automatically gets unchecked.
我不知道为什么。我找到的唯一解决方案是通过SQL查询。我可以在保存后添加一个操作来运行查询,但我想知道问题出在哪里。
register_post_type( \'ott_products\',
array(
\'labels\' => array(
\'name\' => __( \'OhTheThings Products\' ),
\'singular_name\' => __( \'OhTheThings Product\' ),
\'add_new\' => __( \'Add New\' ),
\'add_new_item\' => __( \'Add New Product Listing\' ),
\'edit\' => __( \'Edit\' ),
\'edit_item\' => __( \'Edit Product Listing\' ),
\'new_item\' => __( \'New Product Listing\' ),
\'view\' => __( \'View Product\' ),
\'view_item\' => __( \'View Product\' ),
\'search_items\' => __( \'Search Products\' ),
\'not_found\' => __( \'No product found\' ),
\'not_found_in_trash\' => __( \'No product found in Trash\' ),
\'parent\' => __( \'Parent Product\' )
),
\'public\' => true, // Can be seen/edited by public.
\'menu_position\' => 5, //Position, in this case, just after post.
\'supports\' => array( \'comments\', \'title\', \'editor\', \'thumbnail\' ),
\'taxonomies\' => array( \'category\' ),
\'rewrite\' => array( \'slug\' => \'product\' ),
)
);
这是我的帖子类型的代码,但我真的认为这不相关。
编辑:正在生成和保存自定义字段的代码。。。
function display_product_info_meta_box($post) {
wp_nonce_field( plugin_basename( __FILE__ ), \'ott_checknonce\' );
$price = get_post_meta($post->ID, \'price\', true);
$viaTitle = get_post_meta($post->ID, \'viaTitle\', true);
$viaLink = get_post_meta($post->ID, \'viaLink\', true);
$learnmore = get_post_meta($post->ID, \'learnmore\', true);
$description = get_post_meta($post->ID, \'description\', true);
$userreview = get_post_meta($post->ID, \'userreview\', true);
$colorscheme = get_post_meta($post->ID, \'colorscheme\', true);
echo \'<table class="form-table">
<tr>
<th><label for="colorscheme">Color Scheme</label></th>
<td>
<input type="text" name="colorscheme" id="colorscheme" value="\'.$colorscheme.\'" size="30" />
<br /><span class="description">Accepted values: green, red, blue, corresponding to geeky, home life, and oh wow respectively.<br>Default value is green, ie, geeky.</span>
</td>
</tr>
<tr>
<th><label for="price">Price (USD)</label></th>
<td>
<input type="text" name="price" id="price" value="\'.$price.\'" size="30" />
<br /><span class="description">The price, in USD</span>
</td>
</tr>
<tr>
<th><label for="viaTitle">Via (Title)</label></th>
<td>
<input type="text" name="viaTitle" id="viaTitle" value="\'.$viaTitle.\'" size="30" />
<br /><span class="description">Example: \\\'Amazon\\\' will output \\\'Via Amazon\\\'</span>
</td>
</tr>
<tr>
<th><label for="viaLink">Via (Link)</label></th>
<td>
<input type="text" name="viaLink" id="viaLink" value="\'.$viaLink.\'" size="30" />
<br /><span class="description">The link to go in the \\\'via\\\'</span>
</td>
</tr>
<tr>
<th><label for="learnmore">Learn More URL</label></th>
<td>
<input type="text" name="learnmore" id="learnmore" value="\'.$learnmore.\'" size="30" />
<br /><span class="description">The url the \\\'Learn More\\\' button should lead to.</span>
</td>
</tr>
<tr>
<th><label for="description">Poem/Description</label></th>
<td>
<textarea name="description" id="description" cols="60" rows="15">\'.$description.\'</textarea>
<br /><span class="description">The poem/description. Try and keep it short :)</span>
</td>
</tr>
<tr>
<th><label for="userreview">Featured User Review/Product Features</label></th>
<td>
<textarea name="userreview" id="userreview" cols="60" rows="15">\'.$userreview.\'</textarea>
<br /><span class="description">The \\\'Featured User Review/Product features\\\' field. Please prepend with \\\'<h1>Featured User Review</h1>: \\\' if it\\\'s a user review</span>
</td>
</tr>
</table>\'; // end table
};
function ottycb_save_postdata($post_id) {
if ( defined( \'DOING_AUTOSAVE\' ) && DOING_AUTOSAVE )
return;
if ( !wp_verify_nonce( $_POST[\'ott_checknonce\'], plugin_basename( __FILE__ ) ) )
return;
update_post_meta($post_id, "price", $_POST["price"]);
update_post_meta($post_id, "viaTitle", $_POST["viaTitle"]);
update_post_meta($post_id, "viaLink", $_POST["viaLink"]);
update_post_meta($post_id, "learnmore", $_POST["learnmore"]);
update_post_meta($post_id, "description", $_POST["description"]);
update_post_meta($post_id, "userreview", $_POST["userreview"]);
update_post_meta($post_id, "colorscheme", $_POST["colorscheme"]);
};