VARIS VONGUEA-AREE

PHP 🐍 Python 🔥 Golang 🇹🇭 Bangkok Thailand

High level experience in web design and development knowledge, producing quality work.

For more info
  • Home
  • About
  • Project
  • Blog
  • Varisz
  • Wordpress CMS
  • WordPress Custom Post Type

WordPress Custom Post Type

ถ้าอยากให้ url สามารถเข้าได้จากภายนอกให้ใส่ flush_rewrite_rules(false); ในไฟล์ function.php

  • คำสั่ง get field “get_post_meta( get_the ID(), ‘ชื่อฟิลด์’ , true)”
  • สามารถสร้าง template แสดง type นี้โดยเฉพาะได้ที่ single-ชื่อประเภท.php
function my_custom_post_cars() {

    $labels = array(

        'name'               => _x( 'Cars', 'post type general name' ),
        'singular_name'      => _x( 'Car', 'post type singular name' ),
        'add_new'            => _x( 'Add New Car', 'car' ),
        'add_new_item'       => __( 'Add New Car' ),
        'edit_item'          => __( 'Edit Car' ),
        'new_item'           => __( 'New Car' ),
        'all_items'          => __( 'All Cars' ),
        'view_item'          => __( 'View car' ),
        'search_items'       => __( 'Search car' ),
        'not_found'          => __( 'No car found' ),
        'not_found_in_trash' => __( 'No car found in the Trash' ),
        'parent_item_colon'  => '',
        'menu_name'          => ' Car Catalog',
    );

    $args = array( //on dashboard tool 

        'labels'        => $labels,
        'description'   => 'Holds our cars and cars specific data',
	'public'        => true,
        'menu_position' => 10,
        'supports'      => array( 'title', 'thumbnail',  ),
        'has_archive'   => true,
        'rewrite'       =>true,
        '_builtin' => false, // It's a custom post type, not built in!
	'_edit_link' => 'post.php?post=%d',
	'capability_type' => 'post',
	'hierarchical' => false,
        'rewrite'      => array('slug' => '/cars', 'with_front' => false),

    );

    register_post_type( 'cars', $args );

}
add_action( 'init', 'my_custom_post_cars' );

© 2021 All rights reserved by varisz