How to create custom post type same as another post type in wordpress

29 Views Asked by At

I am using the gettree theme in WordPress.

There is a custom post type called "service" in the theme. I want to create exactly the same post type with a different name and link.

These are the codes I could find in the theme related to service:

  • single-service.php in the gettree main folder
  • archive-service.php in the gettree main folder
  • content-service.php in the theme part
  • taxonomy-service.php in the gettree main folder

And by duplicating these files, they are named according to the post type I want:

  • single-peyzaj_bakimi.php in the gettree main folder
  • archive-peyzaj_bakimi.php in the gettree main folder
  • content-peyzaj-bakimi.php in the theme part
  • taxonomy-peyzaj_bakimi.php in the gettree main folder

Here are the codes related to registering the post type:

// plugins/tfl-core/includes/class-tfl-register-post-type.php location

add_action('init', array($this, 'tfl_register_peyzaj_bakimi'));
add_action('init', array($this, 'tfl_register_peyzaj_bakimi_category'));

// Other functions continue here...

function tfl_register_peyzaj_bakimi() {
    $peyzaj_slug = 'peyzaj-bakimi';
    $labels = array(
        'name'                  => esc_html__( 'Peyzaj Bakımı', 'tfl' ),
        'singular_name'         => esc_html__( 'Peyzaj Bakımı', 'tfl' ),
        'menu_name'             => esc_html__( 'Peyzaj Bakımı', 'tfl' ),
        'add_new'               => esc_html__( 'New Peyzaj Bakımı', 'tfl' ),
        'add_new_item'          => esc_html__( 'Add New Peyzaj Bakımı', 'tfl' ),
        'new_item'              => esc_html__( 'New Peyzaj Bakımı Item', 'tfl' ),
        'edit_item'             => esc_html__( 'Edit Peyzaj Bakımı Item', 'tfl' ),
        'view_item'             => esc_html__( 'View Peyzaj Bakımı', 'tfl' ),
        'all_items'             => esc_html__( 'All Peyzaj Bakımı', 'tfl' ),
        'search_items'          => esc_html__( 'Search Peyzaj Bakımı', 'tfl' ),
        'not_found'             => esc_html__( 'No Peyzaj Bakımı Items Found', 'tfl' ),
        'not_found_in_trash'    => esc_html__( 'No Peyzaj Bakımı Items Found In Trash', 'tfl' ),
        'parent_item_colon'     => esc_html__( 'Parent Peyzaj Bakımı:', 'tfl' ),
        'not_found'             => esc_html__( 'No Peyzaj Bakımı found', 'tfl' ),
        'not_found_in_trash'    => esc_html__( 'No Peyzaj Bakımı found in Trash', 'tfl' )
    );
    $args = array(
        'labels'      => $labels,
        'rewrite'               => array( 'slug' => $peyzaj_slug ),
        'supports'    => array( 'title', 'editor', 'thumbnail','excerpt' ),
        'public'      => true,
        'has_archive' => true,
        'menu_icon'   => 'dashicons-admin-tools',
    );
    register_post_type( 'peyzaj_bakimi', $args );
    flush_rewrite_rules();
}

function tfl_register_peyzaj_bakimi_category() {
    $labels = array(
        'name'                       => esc_html__( 'Peyzaj Bakımı Kategorileri', 'tfl' ),
        'singular_name'              => esc_html__( 'Peyzaj Bakımı Kategorisi', 'tfl' ),
        'search_items'               => esc_html__( 'Search Peyzaj Bakımı Kategorileri', 'tfl' ),
        'menu_name'                  => esc_html__( 'Peyzaj Bakımı Kategorileri', 'tfl' ),
        'all_items'                  => esc_html__( 'Tüm Peyzaj Bakımı Kategorileri', 'tfl' ),
        'parent_item'                => esc_html__( 'Üst Kategori', 'tfl' ),
        'parent_item_colon'          => esc_html__( 'Üst Kategori:', 'tfl' ),
        'new_item_name'              => esc_html__( 'Yeni Kategori Adı', 'tfl' ),
        'add_new_item'               => esc_html__( 'Yeni Kategori Ekle', 'tfl' ),
        'edit_item'                  => esc_html__( 'Kategoriyi Düzenle', 'tfl' ),
        'update_item'                => esc_html__( 'Kategoriyi Güncelle', 'tfl' ),
        'add_or_remove_items'        => esc_html__( 'Kategorileri Ekle veya Kaldır', 'tfl' ),
        'choose_from_most_used'      => esc_html__( 'En Çok Kullanılanlardan Seç', 'tfl' ),
        'not_found'                  => esc_html__( 'Kategori Bulunamadı', 'tfl' ),
    );
    $args = array(
        'labels'       => $labels,
        'hierarchical' => true,
    );
    register_taxonomy( 'peyzaj_bakimi_category', 'peyzaj_bakimi', $args );
    flush_rewrite_rules();
}

// Other functions continue here...

I created it by just changing the service names to peyzaj bakimi. After that, I added the metabox in the service to peyzaj bakimi.

// plugins/tfl-core/includes/class-tfl-register-metabox-type.php location

// Peyzaj Bakımı özel yayın türü için metabox ekle
add_meta_box(
    'tfl-metabox-multiple-fields-peyzaj',
    'Metabox Fields',
    array($this, 'tfl_add_multiple_fields'), // Callback işlevi
    'peyzaj_bakimi'
);

Now, there are differences from the service of which I created an exact copy as follows:

For example, on the all the services are located: ksfkds.com/services/ and this page and the page where all the Landscape maintenance items are located are not the same, there are errors in the front-end.

When I while editing with Elementor, I cannot edit or add anything to the main content section of landscape maintenance with Elementor. Instead, I have to open a new div from the bottom of all the contents and edit it.

If you're wondering what my real question is? How can I create an exact replica of this service called landscape maintenance? Where did I go wrong? And how can I edit the content of the home page where all these services are located?

The link to the service page is below but I changed the name: Peyzaj Uygulamaları https://www.yesilevren.com/peyzaj-uygulamalari/

0

There are 0 best solutions below