获取类别的ID

时间:2018-04-25 07:43:16

标签: php wordpress

我是这个wordpress的新手,我创建了一个CPT,它可以让我添加服务,这些服务是按类别嵌套的,所以我想根据输入的类别提供每个类别的服务。< / p>

我希望你能帮助我,谢谢

升级: 我用以下代码创建了一个PT

function create_servicios_cpt(){

<div v-repeat="myObj">
 <span v-if="$index === (myObj.length-1)">Shows if it is the last loop element</span>
</div>

} add_action(&#39; init&#39;,&#39; create_servicios_cpt&#39;,0);

和分类标准:

/ Taxonomy Key:categoria function create_categoria_tax(){

$labels = array(
    'name' => __( 'Servicios', 'Post Type General Name', 'textdomain' ),
    'singular_name' => __( 'Servicios', 'Post Type Singular Name', 'textdomain' ),
    'menu_name' => __( 'Servicios', 'textdomain' ),
    'name_admin_bar' => __( 'Servicios', 'textdomain' ),
    'archives' => __( 'Archivos Servicios', 'textdomain' ),
    'attributes' => __( 'Atributos Servicios', 'textdomain' ),
    'parent_item_colon' => __( 'Padres Servicios:', 'textdomain' ),
    'all_items' => __( 'Servicios', 'textdomain' ),
    'add_new_item' => __( 'Añadir nueva Servicios', 'textdomain' ),
    'add_new' => __( 'Añadir nuevo', 'textdomain' ),
    'new_item' => __( 'Nueva Servicios', 'textdomain' ),
    'edit_item' => __( 'Editar Servicios', 'textdomain' ),
    'update_item' => __( 'Actualizar Servicios', 'textdomain' ),
    'view_item' => __( 'Ver Servicios', 'textdomain' ),
    'view_items' => __( 'Ver Custom Posts', 'textdomain' ),
    'search_items' => __( 'Buscar Servicios', 'textdomain' ),
    'not_found' => __( 'No se encontraron Custom Posts.', 'textdomain' ),
    'not_found_in_trash' => __( 'Ningún Servicios encontrado en la papelera.', 'textdomain' ),
    'featured_image' => __( 'Imagen destacada', 'textdomain' ),
    'set_featured_image' => __( 'Establecer imagen destacada', 'textdomain' ),
    'remove_featured_image' => __( 'Borrar imagen destacada', 'textdomain' ),
    'use_featured_image' => __( 'Usar como imagen destacada', 'textdomain' ),
    'insert_into_item' => __( 'Insertar en la Servicios', 'textdomain' ),
    'uploaded_to_this_item' => __( 'Subido a esta Servicios', 'textdomain' ),
    'items_list' => __( 'Lista de Custom Posts', 'textdomain' ),
    'items_list_navigation' => __( 'Navegación por el listado de Custom Posts', 'textdomain' ),
    'filter_items_list' => __( 'Lista de Custom Posts filtradas', 'textdomain' ),
);
$args = array(
    'label' => __( 'Servicios', 'textdomain' ),
    'description' => __( '', 'textdomain' ),
    'labels' => $labels,
    'menu_icon' => 'dashicons-tag',
    'supports' => array('title', 'editor', 'thumbnail', ),
    'taxonomies' => array('Categoria', ),
    'public' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'menu_position' => 5,
    'show_in_admin_bar' => true,
    'show_in_nav_menus' => true,
    'can_export' => true,
    'has_archive' => true,
    'hierarchical' => false,
    'exclude_from_search' => false,
    'show_in_rest' => true,
    'publicly_queryable' => true,
    'capability_type' => 'page',
);
register_post_type( 'servicios', $args );

} add_action(&#39; init&#39;,&#39; create_categoria_tax&#39;);

然后,在创建新的&#34;服务&#34;,正常的服务以及类别时,我的问题是显示每个服务的类别。

在我的逻辑中,我会调用一个模板,在此我将验证正在调用的类别的id,并且我将调用此类别的所有服务,但我不明白如何执行此操作。

1 个答案:

答案 0 :(得分:1)

希望它能帮到你