C
C
caof192020-04-30 19:11:41
WordPress
caof19, 2020-04-30 19:11:41

How to get custom post type id?

Hello, I need to get the id of a custom type post by url. The record type is written like this:

register_post_type('uslugi', array(
        'labels'             => array(
            'name'               => '', // Основное название типа записи
            'singular_name'      => '', // отдельное название записи типа Book
            'add_new'            => ' новую',
            'add_new_item'       => 'новую ',
            'edit_item'          => 'Редактировать ',
            'new_item'           => 'Новая ',
            'view_item'          => 'Посмотреть ',
            'search_items'       => 'Найти ',
            'not_found'          =>  'не найдено',
            'not_found_in_trash' => 'В корзине не найдено',
            'parent_item_colon'  => '',
            'menu_name'          => ''

        ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => true,
        'capability_type'    => 'post',
        'has_archive'        => false,
        'hierarchical'       => true,
        'menu_position'      => null,
        'supports'           => array('title','editor','author','thumbnail', 'page-attributes')
    ) );
}

Tried url_to_postid but it seems to only work for regular post type

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nastya, 2020-05-02
@caof19

<?php	
$url = get_the_permalink();
$post_ID = url_to_postid($url);
echo "ID поста = ". $post_ID;	
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question