如何在REGISTER_TASTIONY中显示META数组

时间:2019-12-11 作者:Eudes Tenório

如何让“META”字段在填写的内容中去掉“META:[]”?我正在使用此代码:

register_taxonomy( \'job_listing_category\', \'job_listing\', [
            \'labels\' => [
                \'name\'              => _x( \'Categories\', \'Category taxonomy labels\', \'my-listing\' ),
                \'singular_name\'     => _x( \'Category\', \'Category taxonomy labels\', \'my-listing\' ),
                \'menu_name\'         => _x( \'Categories\', \'Category taxonomy labels\', \'my-listing\' ),
                \'search_items\'      => _x( \'Search Categories\', \'Category taxonomy labels\', \'my-listing\' ),
                \'all_items\'         => _x( \'All Categories\', \'Category taxonomy labels\', \'my-listing\' ),
                \'parent_item\'       => _x( \'Parent Category\', \'Category taxonomy labels\', \'my-listing\' ),
                \'parent_item_colon\' => _x( \'Parent Category:\', \'Category taxonomy labels\', \'my-listing\' ),
                \'edit_item\'         => _x( \'Edit Category\', \'Category taxonomy labels\', \'my-listing\' ),
                \'update_item\'       => _x( \'Update Category\', \'Category taxonomy labels\', \'my-listing\' ),
                \'add_new_item\'      => _x( \'Add New Category\', \'Category taxonomy labels\', \'my-listing\' ),
                \'new_item_name\'     => _x( \'New Category Name\', \'Category taxonomy labels\', \'my-listing\' ),
            ],
            \'rewrite\' => [
                \'slug\' => $permalink_structure[\'category_base\'],
                \'with_front\'   => false,
                \'hierarchical\' => false,
            ],
            \'hierarchical\'          => true,
            \'update_count_callback\' => \'_update_post_term_count\',
            \'show_ui\'               => true,
            \'show_tagcloud\'         => false,
            \'public\'                => true,
            \'show_in_rest\'          => true,
        ] );

1 个回复
SO网友:Krishna Savani

您可以从json获取数组,如下所示:

$request = wp_remote_get( \'https://parquedasfeiras.online/wp-json/wp/v2/job_listing\' );
if( is_wp_error( $request ) ) {
    return false; // Bail early
}
$body = wp_remote_retrieve_body( $request );
$data = json_decode( $body );
if( ! empty( $data ) ) {

    foreach($data  as $subdata){
        print_r($subdata->meta);
    }

}