support.cubewp.com support.cubewp.com
  • Helpdesk
  • Support Forum
Get CubeWP
support.cubewp.com support.cubewp.com
Get CubeWP
support.cubewp.com
  • Helpdesk
  • Support Forum

Docy

CubeWP Framework

  • getting startGetting Started
    • Introduction
    • Installation
    • Support
    • Billing
  • custom post typeCustom Post Types
  • custom taxonomiesCustom Taxonomies
  • Custom Fields
    • Custom Fields for Post Types
    • Custom Fields for Taxonomies
    • Custom Fields for User Roles
    • Custom Field for Settings
  • Custom Field Types
  • Search Forms
  • search filterSearch Filters
  • setting iconCubeWP Settings
  • exportExport
  • importImport
  • Shortcodes
    • Login Page
    • Custom Field Shortcode
    • Archive Shortcodes
  • GuideGuides
    • How to create Custom archive page?
    • Maps in CubeWP
    • Conditional Fields with Taxonomy
    • Conditional Custom Fields
    • Dropdown Field
    • Checkbox Field
    • Radio Button Field
    • How to create Repeatable Fields ?
    • Conditional Custom Fields with Multiple Taxonomies
    • How to Allow Specific File Types in Media?
    • Relationship Fields
    • Custom CSS on Custom Fields
  • Developer Guides
    • How to Get Data Using WP Rest API in CubeWP?
    • How to add any other post type into CubeWP form builder.
    • How to get value of post-type custom field
    • How to get CubeWP Setting’s field value
    • How to create group of custom fields by code
    • CubeWP Filters & Actions
  • faqFAQs
    • What is CubeWP Framework?
    • Does AppSumo deal include all future extensions?
    • Does CubeWP work with any page builder?
    • How can I display custom field data on a single-post template using any page builder?
    • Does CubeWP compatible with Elementor Dynamic Tags?
    • Is CubeWP compatible with any WordPress theme as well?
    • Does CubeWP work with native WP Gutenberg blocks and 3rd party Guten blocks?
    • Does CubeWP support Full Site Editing (FSE)?
    • Is CubeWP Frontend Pro a Page Builders?
    • Is the CubeWP Framework safe to use on WordPress?
    • Can I create custom post types and taxonomies with CubeWP?
    • Can I create custom fields with CubeWP?
    • Is CubeWP compatible with WooCommerce?
    • How can I translate my CubeWP powered site to another language?
    • Is CubeWP SEO friendly?
    • Can I use CubeWP to build a membership site?
    • Is CubeWP compatible with LearnDash or other LMS plugins?
    • Can I create a multivendor marketplace with CubeWP?
    • Can a Non Developer use CubeWP Framework?
    • How do I get support for CubeWP?
    • What are the minimum requirements?
    • Can I use CubeWP without Elementor?
    • Does CubeWP have a refund policy?
    • Is CubeWP WordPress Multisite compatible?
    • Which page builders are compatible?
    • Is the current CubeWP deal on AppSumo a Lifetime Deal?
    • Which themes are compatible?
    • Can I create custom Gutenberg blocks with CubeWP?
    • Does CubeWP work with my WordPress Theme?
    • How often is CubeWP updated?
    • Does CubeWP support Shortcodes?
    • Is CubeWP GDPR-compliant?
    • Does CubeWP work with e-commerce plugins?
    • Does CubeWP offer any built-in caching or performance optimization features?
    • How many Field Types are available in CubeWP?
    • Why my Conditional Logic is not working while creating Custom Fields?
    • Can I export or import my CubeWP settings?
    • Are there any known conflicts with other WordPress plugins?
    • Where can I see all my purchases?
    • Can I Import and Export data from CubeWP?
    • Can I use CubeWP on my clients’ websites?
    • How to activate and manage licenses?
    • Does CubeWP have a refund policy?
    • Does CubeWP support Elementor Dynamic Tag?
    • Are there any live example of customer websites built with CubeWP?
    • Is there a demo website for CubeWP?
    • Do I need Elementor Pro for Dynamic Tags?
    • What is CubeWP Frontend Pro?
    • Is CubeWP Frontend Pro a Page Builder?

How to Get Data Using WP Rest API in CubeWP?

Estimated reading: 5 minutes 622 views
CubeWP allows users to view and manage custom fields via the WordPress REST API. This allows developers to access and edit their custom field data using default WP REST API endpoints

Enable Your Rest API for your Custom Fields

By default, custom fields are not visible in the WP REST API. You must turn it on if you want them to show in the WP REST API. You can enable REST API data for a specific field while creating a field.

What values do you access in CubeWP with WP Rest API?

We are using the default WordPress API in CubeWP, and we extend the default WordPress options get_post_meta and update_post_meta in cubewp_post_meta.
As we are using WP Rest API and rendering the data, users can use the below arguments to get the data.
get_taxonomies -> taxonomies
get_user_meta -> cubewp_user_meta
get_term_meta -> cubewp_term_meta
The WP Rest API exposes various endpoints and parameters to get and update the data. Among these parameters, fields_type, field_name, and post_id are essential for extracting custom field data from CubeWP Custom Fields.
"cubewp_post_meta":{
      "cwp_field_845583830869":{
         "type":"number",
         "meta_key":"cwp_field_845583830869",
         "meta_value":"76",
         "label":"Property Size"
      },
      "cwp_field_671099090382":{
         "type":"number",
         "meta_key":"cwp_field_671099090382",
         "meta_value":"166",
         "label":"Price"
      },
      "cwp_field_605099778660":{
         "type":"google_address",
         "meta_key":"cwp_field_605099778660",
         "meta_value":{
            "address":"",
            "lat":"",
            "lng":""
         },
         "label":"Plot location"
      },
      "cwp_field_569484225099":{
         "type":"dropdown",
         "meta_key":"cwp_field_569484225099",
         "meta_value":"Hostel",
         "label":"Property Type"
      },
      "cwp_field_353853771873":{
         "type":"number",
         "meta_key":"cwp_field_353853771873",
         "meta_value":"1974",
         "label":"Year in built"
      },
      "cwp_field_740709386705":{
         "type":"dropdown",
         "meta_key":"cwp_field_740709386705",
         "meta_value":"6",
         "label":"Bedroom"
      },
      "cwp_field_740709386705356085c78c":{
         "type":"dropdown",
         "meta_key":"cwp_field_740709386705356085c78c",
         "meta_value":"3",
         "label":"Bathrooms"
      },
      "cwp_field_740709386705356085f69d":{
         "type":"dropdown",
         "meta_key":"cwp_field_740709386705356085f69d",
         "meta_value":"3",
         "label":"Car Parking"
      },
      "cwp_field_183772329365":{
         "type":"gallery",
         "meta_key":"cwp_field_183772329365",
         "meta_value":"",
         "label":"Property Images"
      },
      "cwp-gender":{
         "type":"radio",
         "meta_key":"cwp-gender",
         "meta_value":"Male",
         "label":"Gender"
      },
      "cwp_field_574701259039":{
         "type":"number",
         "meta_key":"cwp_field_574701259039",
         "meta_value":"",
         "label":"paternity leaves"
      },
      "cwp_field_816102110789":{
         "type":"text",
         "meta_key":"cwp_field_816102110789",
         "meta_value":"Voluptatem odit sint",
         "label":"male dependent"
      }
   },

Custom routes to fetch Custom Fields and their render values

For all custom fields of custom post type or user custom fields by field type.

site_url/wp-json/cubewp-custom-fields/v1/custom_fields?fields_type={fields_type_value}&fields_source={custom_post_type_slug}&fields_input_type={field_type}
This route is used to fetch all custom fields of custom post type or user custom fields by field type.

Parameters:

fields_type{fields_type_value}:

  • Developers can replace {fields_type_value} with either post_custom_fields or user_custom_fields based on their requirements.
  • Choosing post_custom_fields instructs the API to retrieve custom fields associated with posts, while user_custom_fields would fetch custom fields linked to user profiles.

fields_source{custom_post_type_slug}:

  • The {custom_post_type_slug} placeholder represents the slug of a custom post type created using CubeWP Custom Fields.
  • By specifying the slug of a custom post type, developers can target custom fields associated specifically with that post type.
fields_input_type{fields_type}:
  • Replace {field_type} with the desired input type of the custom fields, such as text, dropdown, number, radio, or checkbox.

To fetch the value of custom fields from posts:

site_url/wp-json/cubewp-custom-fields/v1/custom_fields?fields_type={fields_type_value}&fields_source={custom_post_type_slug}&fields_input_type={field_type}

Parameters:

fields_type:

The fields_type parameter specifies the type of fields to retrieve from the CubeWP Custom Fields plugin. In the context of CubeWP, this parameter can have two main values:

  • post_custom_fields: This value instructs the API to retrieve custom fields associated with a specific post.
  • user_custom_fields: Alternatively, if CubeWP extends its functionality to user profiles, this value could retrieve custom fields associated with user profiles.

field_name:

The field_name parameter allows developers to specify the name of the custom field they want to extract. CubeWP Custom Fields enables users to create and manage custom fields with unique identifiers. By providing the field_name parameter, developers can retrieve the value of a specific custom field associated with a post or user.

post_id:

The post_id parameter specifies the ID of the post from which custom field data should be retrieved. Each post in WordPress has a unique numerical identifier, and providing this ID ensures that the API fetches custom field data for the specified post.


/wp-json/cubewp-custom-fields/v1/render?fields_type=post_custom_fields&field_name=cwp_field_845583830869&post_id=113

In this example:

  • fields_type is set to post_custom_fields, indicating that we want to retrieve custom fields associated with a post.
  • field_name is specified as cwp_field_845583830869, denoting the unique identifier of the custom field we’re interested in.
  • post_id is set to 113, indicating the specific post from which we want to fetch the custom field data.

Share this Doc

How to Get Data Using WP Rest API in CubeWP?

Or copy link

Clipboard Icon
CONTENTS
Leaf Illustration

© 2023 All Rights Reserved by CubeWP