自定义帖子类型缺少WP REST API分类

时间:2017-07-30 作者:Erdinç Taze

我使用wp-restapiv2插件。自定义帖子类型不显示分类法。有人能告诉我怎么了吗?

URL:wp json/wp/v2/galeri_嵌入

{
"id": 275,
"date": "2016-05-07T23:53:17",
"date_gmt": "2016-05-07T20:53:17",
"guid": {
    "rendered": "http:\\/\\/demo.markamiz.com\\/?post_type=galeri&p=275"
},
"modified": "2017-07-21T15:07:24",
"modified_gmt": "2017-07-21T12:07:24",
"slug": "samsung-galaxy-s7-edge",
"status": "publish",
"type": "galeri",
"link": "http:\\/\\/www.teknoever.com\\/galeri\\/samsung-galaxy-s7-edge\\/",
"title": {
    "rendered": "Samsung Galaxy S7 Edge"
},
"content": {
    "rendered": "<p>Toplam <b>7<\\/b> sayfadan <b>1.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-276\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150604_samsung-galaxy-s7-1445005423.jpg\\" alt=\\"150604_samsung-galaxy-s7-1445005423\\" width=\\"580\\" height=\\"356\\" \\/><br \\/>\\n<!--nextpage--><br \\/>\\nToplam <b>7<\\/b> sayfadan <b>2.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-277\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150604_samsung-galaxy-s7-edge-concept-renders.jpg\\" alt=\\"150604_samsung-galaxy-s7-edge-concept-renders\\" width=\\"580\\" height=\\"386\\" \\/><br \\/>\\n<!--nextpage--><br \\/>\\nToplam <b>7<\\/b> sayfadan <b>3.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-278\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-1.jpg\\" alt=\\"150605_samsung-galaxy-s7-edge-concept-renders-1\\" width=\\"580\\" height=\\"386\\" \\/><br \\/>\\n<!--nextpage--><br \\/>\\nToplam <b>7<\\/b> sayfadan <b>4.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-279\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-2.jpg\\" alt=\\"150605_samsung-galaxy-s7-edge-concept-renders-2\\" width=\\"580\\" height=\\"386\\" \\/><br \\/>\\n<!--nextpage--><br \\/>\\nToplam <b>7<\\/b> sayfadan <b>5.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-280\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-3-1445005456.jpg\\" alt=\\"150605_samsung-galaxy-s7-edge-concept-renders-3-1445005456\\" width=\\"580\\" height=\\"385\\" \\/><br \\/>\\n<!--nextpage--><br \\/>\\nToplam <b>7<\\/b> sayfadan <b>6.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-281\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150606_samsung-galaxy-s7-edge-concept-renders-4.jpg\\" alt=\\"150606_samsung-galaxy-s7-edge-concept-renders-4\\" width=\\"580\\" height=\\"386\\" \\/><br \\/>\\n<!--nextpage--><br \\/>\\nToplam <b>7<\\/b> sayfadan <b>7.<\\/b> sayfadas\\u0131n\\u0131z.<br \\/>\\n<img class=\\"alignnone size-full wp-image-282\\" src=\\"http:\\/\\/demo.markamiz.com\\/wp-content\\/uploads\\/2016\\/05\\/150606_samsung-galaxy-s7-edge-concept-renders-5-1.jpg\\" alt=\\"150606_samsung-galaxy-s7-edge-concept-renders-5\\" width=\\"580\\" height=\\"386\\" \\/><\\/p>\\n",
    "protected": false
},
"excerpt": {
    "rendered": "<p>Y\\u0131l\\u0131n en dikkat \\u00e7ekici modellerinden bir tanesi olan Samsung Galaxy S7 edge, inceleme merkezimizin yeni konu\\u011fu oluyor.<br \\/>\\nSamsung, ge\\u00e7ti\\u011fimiz y\\u0131l sat\\u0131\\u015fa sundu\\u011fu Galaxy S6 ve Galaxy S6 edge modelleriyle tasar\\u0131m dilinde ciddi bir de\\u011fi\\u015fikli\\u011fe gitmi\\u015f, plastik tasar\\u0131m\\u0131 tarihin tozlu sayfalar\\u0131nda b\\u0131rakarak cam ve metal malzemelerle haz\\u0131rlanan premium tasar\\u0131mlar\\u0131 bizlere sunmu\\u015ftu. \\u00d6zellikle S6 edge ve daha sonra sat\\u0131\\u015fa sunulan S6 edge+, y\\u0131l\\u0131n en \\u015f\\u0131k modelleri aras\\u0131nda g\\u00f6sterilmi\\u015fti.<\\/p>\\n",
    "protected": false
},
"author": 4,
"featured_media": 7825,
"menu_order": 0,
"comment_status": "open",
"ping_status": "open",
"template": "",
"meta": [],
"acf": [],
"_links": {
    "self": [{
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/galeri\\/275"
    }],
    "collection": [{
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/galeri"
    }],
    "about": [{
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/types\\/galeri"
    }],
    "author": [{
        "embeddable": true,
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/users\\/4"
    }],
    "replies": [{
        "embeddable": true,
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/comments?post=275"
    }],
    "version-history": [{
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/galeri\\/275\\/revisions"
    }],
    "wp:featuredmedia": [{
        "embeddable": true,
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/media\\/7825"
    }],
    "wp:attachment": [{
        "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/media?parent=275"
    }],
    "curies": [{
        "name": "wp",
        "href": "https:\\/\\/api.w.org\\/{rel}",
        "templated": true
    }]
},
"_embedded": {
    "author": [{
        "id": 4,
        "name": "Erdin\\u00e7",
        "url": "http:\\/\\/www.teknoever.com",
        "description": "Uzun y\\u0131llar bir\\u00e7ok blog ve haber portallar\\u0131nda edit\\u00f6r olarak \\u00e7al\\u0131\\u015fmas\\u0131n\\u0131n yan\\u0131nda, asp ve php yaz\\u0131l\\u0131mlar\\u0131na olduk\\u00e7a hakim ve bir\\u00e7ok projede b\\u00fcy\\u00fck ba\\u015far\\u0131lara imza atm\\u0131\\u015ft\\u0131r. Edit\\u00f6rl\\u00fck kariyerinde \\u015fimdi Tekno Ever ile devam etmektedir.Referanslar i\\u00e7in l\\u00fctfen markamiz.com\'u ziyaret ediniz.",
        "link": "http:\\/\\/www.teknoever.com\\/yazar\\/erdinc\\/",
        "slug": "erdinc",
        "avatar_urls": {
            "24": "http:\\/\\/2.gravatar.com\\/avatar\\/b37cac9cdbbc2f7cdae3348e514a305b?s=24&d=mm&r=g",
            "48": "http:\\/\\/2.gravatar.com\\/avatar\\/b37cac9cdbbc2f7cdae3348e514a305b?s=48&d=mm&r=g",
            "96": "http:\\/\\/2.gravatar.com\\/avatar\\/b37cac9cdbbc2f7cdae3348e514a305b?s=96&d=mm&r=g"
        },
        "acf": [],
        "_links": {
            "self": [{
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/users\\/4"
            }],
            "collection": [{
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/users"
            }]
        }
    }],
    "wp:featuredmedia": [{
        "id": 7825,
        "date": "2016-09-06T17:31:52",
        "slug": "150605_samsung-galaxy-s7-edge-concept-renders-2",
        "type": "attachment",
        "link": "http:\\/\\/www.teknoever.com\\/galeri\\/samsung-galaxy-s7-edge\\/150605_samsung-galaxy-s7-edge-concept-renders-2\\/",
        "title": {
            "rendered": "150605_samsung-galaxy-s7-edge-concept-renders-2"
        },
        "author": 4,
        "acf": [],
        "caption": {
            "rendered": ""
        },
        "alt_text": "",
        "media_type": "image",
        "mime_type": "image\\/jpeg",
        "media_details": {
            "width": 580,
            "height": 386,
            "file": "2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-2.jpg",
            "sizes": {
                "thumbnail": {
                    "file": "150605_samsung-galaxy-s7-edge-concept-renders-2-150x150.jpg",
                    "width": 150,
                    "height": 150,
                    "mime_type": "image\\/jpeg",
                    "source_url": "http:\\/\\/www.teknoever.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-2-150x150.jpg"
                },
                "medium": {
                    "file": "150605_samsung-galaxy-s7-edge-concept-renders-2-300x200.jpg",
                    "width": 300,
                    "height": 200,
                    "mime_type": "image\\/jpeg",
                    "source_url": "http:\\/\\/www.teknoever.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-2-300x200.jpg"
                },
                "full": {
                    "file": "150605_samsung-galaxy-s7-edge-concept-renders-2.jpg",
                    "width": 580,
                    "height": 386,
                    "mime_type": "image\\/jpeg",
                    "source_url": "http:\\/\\/www.teknoever.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-2.jpg"
                }
            },
            "image_meta": {
                "aperture": "0",
                "credit": "",
                "camera": "",
                "caption": "",
                "created_timestamp": "0",
                "copyright": "",
                "focal_length": "0",
                "iso": "0",
                "shutter_speed": "0",
                "title": "",
                "orientation": "0",
                "keywords": []
            }
        },
        "source_url": "http:\\/\\/www.teknoever.com\\/wp-content\\/uploads\\/2016\\/05\\/150605_samsung-galaxy-s7-edge-concept-renders-2.jpg",
        "_links": {
            "self": [{
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/media\\/7825"
            }],
            "collection": [{
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/media"
            }],
            "about": [{
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/types\\/attachment"
            }],
            "author": [{
                "embeddable": true,
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/users\\/4"
            }],
            "replies": [{
                "embeddable": true,
                "href": "http:\\/\\/www.teknoever.com\\/wp-json\\/wp\\/v2\\/comments?post=7825"
            }]
        }
    }]
}
}

2 个回复
SO网友:Cedon

检查自定义帖子类型和自定义分类参数数组,并确保\'show_in_rest\' 设置为true 两者都有。

SO网友:Erdinç Taze

我解决了我的问题。解决方案如下,如果任何人有此问题,只需在函数中添加以下代码即可。php和type taxonomy name taxonomy\\u name变量

add_action( \'init\', \'my_custom_taxonomy_rest_support\', 25 );
function my_custom_taxonomy_rest_support() {
global $wp_taxonomies;
//be sure to set this to the name of your taxonomy!
$taxonomy_name = \'galeri-kategori\';
if ( isset( $wp_taxonomies[ $taxonomy_name ] ) ) {
$wp_taxonomies[ $taxonomy_name ]->show_in_rest = true;

// Optionally customize the rest_base or controller class
$wp_taxonomies[ $taxonomy_name ]->rest_base = $taxonomy_name;
$wp_taxonomies[ $taxonomy_name ]->rest_controller_class = \'WP_REST_Terms_Controller\';
}
}

结束

相关推荐

customize taxonomy Page

有没有一种解决方案可以自定义分类法页面并使其类似于带有标题h1和自定义侧栏的类别页面?这是我的分类代码:register_taxonomy(\'director\', \'post\', array( \'hierarchical\' => false, \'label\' => \'Realisateur\', \'query_var\' => true, \'rewrite\' => $rewrite2));