有人可以檢查我的代碼,看看我要去的地方錯了,請WordPress的自定義文章類型不鏈接到單property.php和歸檔property.php
<?php
// let's create the function for the custom type
function cmb_property_post_type() {
// creating (registering) the custom type
register_post_type('property', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
// let's now add all the options for this post type
array('labels' => array(
'name' => __('Properties', 'jointstheme'), /* This is the Title of the Group */
'singular_name' => __('Property', 'jointstheme'), /* This is the individual type */
'all_items' => __('All Properties', 'jointstheme'), /* the all items menu item */
'add_new' => __('Add New', 'jointstheme'), /* The add new menu item */
'add_new_item' => __('Add New Property', 'jointstheme'), /* Add New Display Title */
'edit' => __('Edit', 'jointstheme'), /* Edit Dialog */
'edit_item' => __('Edit Property', 'jointstheme'), /* Edit Display Title */
'new_item' => __('New Property', 'jointstheme'), /* New Display Title */
'view_item' => __('View Property', 'jointstheme'), /* View Display Title */
'search_items' => __('Search Property', 'jointstheme'), /* Search Custom Type Title */
'not_found' => __('Nothing found in the Database.', 'jointstheme'), /* This displays if there are no entries yet */
'not_found_in_trash' => __('Nothing found in Trash', 'jointstheme'), /* This displays if there is nothing in the trash */
'parent_item_colon' => ''
), /* end of arrays */
'description' => __('All properties are displayed in google maps', 'jointstheme'), /* Custom Type Description */
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/', /* the icon for the custom post type menu */
'rewrite' => array('slug' => 'properties', 'with_front' => false), /* you can specify its url slug */
'has_archive' => 'properties', /* you can rename the slug here */
'capability_type' => 'post',
'hierarchical' => false,
/* the next one is important, it tells what's enabled in the post editor */
'supports' => array('title', 'editor', 'author', 'thumbnail', 'revisions')
) /* end of options */
); /* end of register post type */
/* this adds your post categories to your custom post type */
register_taxonomy_for_object_type('category', 'property_cat');
/* this adds your post tags to your custom post type */
register_taxonomy_for_object_type('post_tag', 'property_cat');
}
// adding the function to the Wordpress init
add_action('init', 'cmb_property_post_type');
/*
for more information on taxonomies, go here:
http://codex.wordpress.org/Function_Reference/register_taxonomy
*/
// now let's add custom categories (these act like categories)
register_taxonomy('property_cat',
array('property'), /* if you change the name of register_post_type('custom_type', then you have to change this */
array('hierarchical' => true, /* if this is true, it acts like categories */
'labels' => array(
'name' => __('Categories', 'jointstheme'), /* name of the custom taxonomy */
'singular_name' => __('Category', 'jointstheme'), /* single taxonomy name */
'search_items' => __('Search Categories', 'jointstheme'), /* search title for taxomony */
'all_items' => __('All Categories', 'jointstheme'), /* all title for taxonomies */
'parent_item' => __('Parent Category', 'jointstheme'), /* parent title for taxonomy */
'parent_item_colon' => __('Parent Category:', 'jointstheme'), /* parent taxonomy title */
'edit_item' => __('Edit Category', 'jointstheme'), /* edit custom taxonomy title */
'update_item' => __('Update Category', 'jointstheme'), /* update title for taxonomy */
'add_new_item' => __('Add New Category', 'jointstheme'), /* add new title for taxonomy */
'new_item_name' => __('New Category Name', 'jointstheme') /* name title for taxonomy */
),
'show_admin_column' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'property-cat')
)
);
// now let's add custom tags (these act like categories)
register_taxonomy('property_tag',
array('property'), /* if you change the name of register_post_type('custom_type', then you have to change this */
array('hierarchical' => false, /* if this is false, it acts like tags */
'labels' => array(
'name' => __('Tags', 'jointstheme'), /* name of the custom taxonomy */
'singular_name' => __('Tag', 'jointstheme'), /* single taxonomy name */
'search_items' => __('Search Tags', 'jointstheme'), /* search title for taxomony */
'all_items' => __('All Tags', 'jointstheme'), /* all title for taxonomies */
'parent_item' => __('Parent Tag', 'jointstheme'), /* parent title for taxonomy */
'parent_item_colon' => __('Parent Tag:', 'jointstheme'), /* parent taxonomy title */
'edit_item' => __('Edit Tag', 'jointstheme'), /* edit custom taxonomy title */
'update_item' => __('Update Tag', 'jointstheme'), /* update title for taxonomy */
'add_new_item' => __('Add New Tag', 'jointstheme'), /* add new title for taxonomy */
'new_item_name' => __('New Tag Name', 'jointstheme') /* name title for taxonomy */
),
'show_admin_column' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'property-tag')
)
);
function cmb_marker_properties(array $meta_boxes) {
$fields = array(
array(
'id' => 'properties-marker',
'name' => '',
'type' => 'image',
'file_type' => 'image',
'repeatable' => false,
'sortable' => true,
'cols' => 12
)
);
$group_fields = $fields;
foreach ($group_fields as &$field) {
$field['id'] = str_replace('field', 'gfield', $field['id']);
}
$meta_boxes[] = array(
'title' => 'Map Marker',
'pages' => 'property',
'context' => 'side',
'priority' => 'low',
'fields' => array(
array(
'id' => 'cmb_marker_properties',
//'name' => 'Add related links',
'type' => 'group',
'repeatable' => false,
'sortable' => true,
'fields' => $group_fields
)
)
);
return $meta_boxes;
}
add_filter('cmb_meta_boxes', 'cmb_marker_properties');
function cmb_info_properties(array $meta_boxes) {
$fields = array(
array(
'id' => 'properties-room',
'name' => 'Room',
'type' => 'select',
'options' => array(
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
),
'allow_none' => false,
'cols' => 12
)
);
$group_fields = $fields;
foreach ($group_fields as &$field) {
$field['id'] = str_replace('field', 'gfield', $field['id']);
}
$meta_boxes[] = array(
'title' => 'Property Details',
'pages' => 'property',
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'id' => 'cmb_info_properties',
//'name' => 'Add related links',
'type' => 'group',
'repeatable' => false,
'sortable' => true,
'fields' => $group_fields
)
)
);
return $meta_boxes;
}
add_filter('cmb_meta_boxes', 'cmb_info_properties');?>
我必須託運這無數次,但我仍然無法看到問題出在哪裏,或者我只是看錯了地方?
我也創造了單property.php和存檔property.php
是我得到的問題是,當我創建屬性後類型中的帖子,點擊發布,然後我點擊查看頁面,我得到一個404錯誤。
另一個問題,我認爲可能與上述有關,我無法wp_query
查詢類別。
我嘗試使用此代碼沒有工作:
$args= array(
'post_type' => 'property',
'post_status' => 'publish',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'property_cat',
'term' => 'buy',
)
),
);
可能是什麼問題,如何解決它。
我試過重寫刷新方法,也沒有工作。
更新:重新保存永久鏈接設置後。我的自定義帖子類型頁面已經開始進入主頁。我更困惑
當你點擊** **屬性在THW WP管理員菜單,網址是什麼?我對'post_type'部分感興趣。應該看起來像:http://www.itheco.com/wp-admin/edit.php?post_type=。有時在創建自定義帖子類型時,您可能會意外創建多個帖子。 –
Lasse
它說財產 – Ahmed