1
我在我的網站上有一個名爲clock的自定義帖子類型和一個名爲clock_category的分類。 它運作良好,所有的時鐘可以從REST端點 https://myapp.dev/wp-json/wp/v2/clock如何在最新的Wordpress RESTful API中通過自定義分類過濾自定義帖子類型?
進行訪問,但我不知道如何通過時鐘類別對其進行過濾,說我想所有這些都是木製的鐘
我嘗試了不同的網址,但沒有人似乎工作 https://myapp.dev/wp-json/wp/v2/clock?clock_category=wood https://myapp.dev/wp-json/wp/v2/clock?clock_category=10
等等。我所得到的是完整的結果集。
下面是代碼
<?php
add_action('init', 'clock');
function clock() {
$labels = array(
"name" => __('Clock', 'mywp'),
"singular_name" => __('clock', 'mywp'),
"menu_name" => __('Clock', 'mywp'),
"all_items" => __('All Clock', 'mywp'),
"add_new" => __('Add New Clock', 'mywp'),
"add_new_item" => __('Add New Clock', 'mywp'),
"edit_item" => __('Edit Clock', 'mywp'),
"new_item" => __('New Clock', 'mywp'),
"view_item" => __('View Clock', 'mywp'),
"search_items" => __('Search Clock', 'mywp'),
"not_found" => __('No Clock Found', 'mywp'),
"not_found_in_trash" => __('No Clock found in trash', 'mywp'),
"parent_item_colon" => __('Parent Clock', 'mywp'),
"featured_image" => __('Feature Image for Clock', 'mywp'),
"set_featured_image" => __('Set featured Clock image', 'mywp'),
"remove_featured_image" => __('Remove featured image for Clock', 'mywp'),
"use_featured_image" => __('Use featured image for Clock', 'mywp'),
"archives" => __('Clock archives', 'mywp'),
"insert_into_item" => __('Insert into Clock', 'mywp'),
"uploaded_to_this_item" => __('Uploaded to this Clock', 'mywp'),
"items_list_navigation" => __('Clock list navigation', 'mywp'),
"items_list" => __('Clock List', 'mywp'),
"parent_item_colon" => __('Parent Clock', 'mywp'),
);
$args = array(
"label" => __('Clock', 'mywp'),
"labels" => $labels,
"description" => "Clock",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => true,
"rest_base" => "clock",
"has_archive" => false,
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
"rewrite" => array("slug" => "clock", "with_front" => true),
"query_var" => true,
"supports" => array("title", "editor", "thumbnail", "custom-fields", "page-attributes", "post-formats"),
"taxonomies" => array(),
);
register_post_type("clock", $args);
}
add_action('init', 'create_clock_tax');
function create_clock_tax() {
register_taxonomy(
'clock_category',
'clock',
array(
'label' => __('Clock Category'),
'rewrite' => array('slug' => 'clock_category'),
'hierarchical' => true,
)
);
}
希望有人幫我出這一點。我一直試圖解決這個問題5個小時,似乎沒有任何工作。
你有沒有設法讓這項工作。我也有同樣的問題 –