He registrado un nuevo tipo de publicación personalizada al codificarla en mi tema (sí, ¡podría/debería mover esto a un complemento que conozco!).
Pero cuando se usa el nuevo bloque Query Loop, las únicas opciones en Tipo de publicación son ‘publicaciones’ y ‘páginas’. ¿Falta algo en mi código CPT que causa este problema o podría ser otra cosa?
Gracias por adelantado.
<?php
// Register Custom Post Type
function cpt_listings_function() {
$labels = array(
'name' => _x( 'Listings', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Listing', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Listings', 'text_domain' ),
'name_admin_bar' => __( 'Listings', 'text_domain' ),
'archives' => __( 'Listing Archives', 'text_domain' ),
'attributes' => __( 'Listing Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Listing:', 'text_domain' ),
'all_items' => __( 'All Listings', 'text_domain' ),
'add_new_item' => __( 'Add New Listing', 'text_domain' ),
'add_new' => __( 'Add New Listing', 'text_domain' ),
'new_item' => __( 'New Listing', 'text_domain' ),
'edit_item' => __( 'Edit Listing', 'text_domain' ),
'update_item' => __( 'Update Listing', 'text_domain' ),
'view_item' => __( 'View Listing', 'text_domain' ),
'view_items' => __( 'View Listings', 'text_domain' ),
'search_items' => __( 'Search Listing', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into listing', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this Listing', 'text_domain' ),
'items_list' => __( 'Listings list', 'text_domain' ),
'items_list_navigation' => __( 'Listings list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter listings list', 'text_domain' ),
);
$rewrite = array(
'slug' => 'listing',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'label' => __( 'Listing', 'text_domain' ),
'description' => __( 'Property Listings Custom Post Type', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'page-attributes', 'author' ),
'taxonomies' => array(),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 100,
'menu_icon' => 'dashicons-admin-multisite',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => 'listings',
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => $rewrite,
'capability_type' => array( 'listing', 'listings' ),
'map_meta_cap' => true,
);
register_post_type( 'post_type_listings', $args );
}
add_action( 'init', 'cpt_listings_function', 0 );
Resolví esto agregando el siguiente código a mi función de tipo de publicación personalizada anterior:
'show_in_rest' => true,
Más información aquí: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/
-
Como nota, ‘publicly_queryable’ también debe establecerse en verdadero
– Vladan
6 de julio a las 13:48