Create Custom Post Typesand Manage Them with theWordPress REST API

Create Custom Post Types and Manage Them with the WordPress REST API

Jul 28, 2025 |

12 minutes read

Create Custom Post Typesand Manage Them with theWordPress REST API

WordPress Custom Post Types Integration with REST API

If you want more control over the type of content your WordPress site handles, custom post types (CPTs) are a great place to start. They let you define entirely new types of content—like events, properties, courses, or anything else your project needs—without being limited to just “Posts” or “Pages.”

What makes them even more powerful is the ability to integrate these custom post types with the WordPress REST API. This gives you full programmatic access to create, update, retrieve, and delete CPT content from external applications, websites, or mobile apps. Whether you’re building a headless front end or working with an enterprise WordPress development agency to sync content between systems, REST API support makes it much easier.

What Are Custom Post Types and Why Use the REST API? 

Custom post types are exactly what they sound like—customized content structures you define in WordPress. You might need one for portfolios, job listings, courses, or real estate listings. By registering a CPT, you can give each type of content its own layout, fields, and behavior.

The REST API, which became a core part of WordPress in version 4.7, allows you to work with this content via HTTP requests (like GET, POST, PUT, and DELETE). Once your CPT is exposed to the API, you can manage it remotely from any system that can make web requests—no need to log into the WordPress admin or rely solely on your WordPress development company.

Real-World Use Cases

To give you an idea of how flexible this setup can be, here are a few practical examples:

  • Real Estate Listings: You can create a property CPT that includes fields like price, square footage, and location. 
  • Job Board: A job CPT might include fields for company name, salary range, job description, and an application URL. 
  • Online Learning: A course CPT can be used to organize your educational content, with custom fields like duration, difficulty level, and a sign-up link. 

Option 1: Creating CPTs with Code

If you’re comfortable with PHP, you can register a CPT by adding this to your theme’s functions.php or creating a custom plugin:



function create_property_post_type() { 
	$labels = array( 
    	'name' => 'Properties', 
    	'singular_name' => 'Property', 
    	'add_new_item' => 'Add New Property', 
    	'edit_item' => 'Edit Property', 
    	'all_items' => 'All Properties', 
    	'menu_name' => 'Properties' 
	); 
	$args = array( 
    	'labels' => $labels, 
    	'public' => true, 
    	'show_in_rest' => true, 
    	'has_archive' => true, 
    	'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'), 
    	'menu_icon' => 'dashicons-building', 
    	'rewrite' => array('slug' => 'properties') 
	); 
	register_post_type('property', $args); 
} 

add_action(‘init’, ‘create_property_post_type’); 

Now your dashboard will have a Properties section, and you can fetch these via: 

https://yoursite.com/wp-json/wp/v2/property 

WordPress REST API Endpoints for Custom Post Types

Once your custom post type is registered with show_in_rest, it becomes available via the WordPress REST API. For the “Properties” post type, the base endpoint is:

https://yourdomain.com/wp-json/wp/v2/property

Key endpoints include: 

  • GET /wp/v2/property — Retrieve all property. 
  • GET /wp/v2/property/{id} — Retrieve a specific property by ID. 
  • POST /wp/v2/property — Create a new property. 
  • PUT /wp/v2/property/{id} — Update an existing property. 
  • DELETE /wp/v2/property/{id} — Delete an property. 

You can also use query parameters for filtering or pagination, such as ?per_page=10 or ?status=publish. 

Option 2: Using Plugins (No Code Required) 

Not a developer? Or just want to save time? Here are plugins that simplify CPT creation and REST API integration:

Custom Post Type UI (CPT UI) 

  • Easiest way to create CPTs and custom taxonomies. 
  • Automatically integrates with the REST API (enable the setting). 
  • Great for beginners and non-developers. 

Pods 

  • More powerful than CPT UI; lets you create CPTs, taxonomies, and custom fields all in one place. 
  • REST API support out of the box. 
  • Best for advanced relational data (e.g., Courses linked to Instructors). 

Advanced Custom Fields (ACF) 

  • While not a CPT plugin by itself, ACF is essential for adding fields like price, location, etc. 
  • ACF Pro supports custom REST API exposure automatically when “Show in REST” is checked. 

Accessing CPTs via the REST API 

Once your CPT is registered (via code or plugin) and show_in_rest is enabled, you can fetch data using: 

https://yoursite.com/wp-json/wp/v2/{post-type} 

Adding Custom Fields to the API 

For real-world use, CPTs usually need extra fields like “price”, “location”, or “job type”. 

If you use ACF: 

  • Create your fields. 
  • Check “Show in REST API” in the field group settings. 
  • Now your fields will automatically appear in API responses. 

Or manually add them: 



function add_property_meta_to_api() { 
	register_rest_field('property', 'price', array( 
	'get_callback' => function($object) { 
    	return get_post_meta($object['id'], 'price', true); 
	}, 
	'schema' => array( 
	'description' => 'Property Price', 
	'type' => 'string' 
	) 
 )); 
} 


add_action(‘rest_api_init’, ‘add_property_meta_to_api’); 

Testing with Postman 

Postman is an excellent tool for testing REST API requests without writing code: 

  • Create a new request in Postman. 
  • Set the method (GET, POST, PUT, DELETE) and enter the endpoint URL (e.g., https://yourdomain.com/wp-json/wp/v2/property). 
  • Under Authorization, select Basic Auth and input your username and application password. 
  • Set the Content-Type header to application/json in the Headers section.
  • For POST or PUT requests, make sure to place your JSON payload in the Body section.
  • Once everything is ready, send the request and check the response to validate or troubleshoot as needed.

Best Practices for Using the WordPress REST API with Custom Post Types 

  • Secure Your API: Always use HTTPS and prefer Application Passwords or OAuth for authentication. 
  • Handle Pagination: For large datasets, use pagination (per_page and page parameters) to avoid performance issues. 
  • Use Nonces for Frontend Requests: For security purposes, always attach WordPress nonces when making API requests from JavaScript.
  • Validate Input Data: Before submitting data to the API, sanitize and validate it to avoid potential errors or vulnerabilities.
  • Monitor Rate Limits: If your API calls are being throttled, use exponential backoff to manage retries more effectively.

Build Smarter with WordPress REST API + CPTs

The Way Forward

By combining Custom Post Types, the WordPress REST API, and plugins like CPT UI, Pods, and ACF, you can transform WordPress into a powerful backend for modern apps, headless sites, or complex portals—without reinventing the wheel. When working with an enterprise WordPress agency, these tools become even more effective, allowing you to build scalable, maintainable, and high-performing solutions.

Whether you’re building a real estate directory, a job board, or a course catalog, CPTs with the REST API make WordPress flexible enough for any project.

Free Consultation

    developers



    MAP_New

    Global Footprints

    Served clients across the globe from38+ countries

    iFlair Web Technologies
    Privacy Overview

    This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.