2014-02-26 93 views
0

有人可以检查我的代码,看看我要去的地方错了,请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', 
     ) 
    ), 
); 

可能是什么问题,如何解决它。

我试过重写刷新方法,也没有工作。

更新:重新保存永久链接设置后。我的自定义帖子类型页面已经开始进入主页。我更困惑

+0

当你点击** **属性在THW WP管理员菜单,网址是什么?我对'post_type'部分感兴趣。应该看起来像:http://www.itheco.com/wp-admin/edit.php?post_type= 。有时在创建自定义帖子类型时,您可能会意外创建多个帖子。 – Lasse

+0

它说财产 – Ahmed

回答

0

你有has_archive => properties它覆盖默认的帖子类型property

更改此:

'has_archive' => 'properties' 

到:

'has_archive' => false 

docs

+0

没有工作rahil。我确定通过设置'has_archive'=>'属性',我将能够使用我的自定义存档页面“archive-property.php”显示我的页面自定义帖子类型。 – Ahmed

+0

您是否使用flush重写规则? –

+0

我用这个代码,但它仍然没有工作: $ set = get_option('post_type_rules_flased_property'); if($ set!== true){ flush_rewrite_rules(false); update_option('post_type_rules_flased_property',true); } – Ahmed

0

我通过使用不同的主题和应用自定义后类型它解决了我的问题。

我的思维方式或如何我加入了我的职务为了有事可做与我的问题

相关问题