title: How To make an API in Wordpress
body: <p>This is my first time i use wordpress for create apps. in there i want to make an api but dont know how to make it in wordpress.</p>
  
  <p>this my code in website :</p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>function drivers_post_type() {
      $labels = array(
          'name'                =&gt; _x( 'driver', 'Post Type General Name', 'text_domain' ),
          'singular_name'       =&gt; _x( 'driver', 'Post Type Singular Name', 'text_domain' ),
          'menu_name'           =&gt; __( 'driver', 'text_domain' ),
          'name_admin_bar'      =&gt; __( 'Post Type', 'text_domain' ),
          'parent_item_colon'   =&gt; __( 'Parent Item:', 'text_domain' ),
          'all_items'           =&gt; __( 'All Items', 'text_domain' ),
          'add_new_item'        =&gt; __( 'Add New Item', 'text_domain' ),
          'add_new'             =&gt; __( 'Add New', 'text_domain' ),
          'new_item'            =&gt; __( 'New Item', 'text_domain' ),
          'edit_item'           =&gt; __( 'Edit Item', 'text_domain' ),
          'update_item'         =&gt; __( 'Update Item', 'text_domain' ),
          'view_item'           =&gt; __( 'View Item', 'text_domain' ),
          'search_items'        =&gt; __( 'Search Item', 'text_domain' ),
          'not_found'           =&gt; __( 'Not found', 'text_domain' ),
          'not_found_in_trash'  =&gt; __( 'Not found in Trash', 'text_domain' ),
      );
      $args = array(
          'label'               =&gt; __( 'driver', 'text_domain' ),
          'description'         =&gt; __( 'driver', 'text_domain' ),
          'labels'              =&gt; $labels,
          'supports'            =&gt; array( 'title','thumbnail' ),
          'hierarchical'        =&gt; false,
          'public'              =&gt; true,
          'show_ui'             =&gt; true,
          'show_in_menu'        =&gt; true,
          'menu_position'       =&gt; 5,
          'show_in_admin_bar'   =&gt; true,
          'show_in_nav_menus'   =&gt; true,
          'can_export'          =&gt; true,
          'has_archive'         =&gt; true,
          'exclude_from_search' =&gt; false,
          'publicly_queryable'  =&gt; true,
          'rewrite'             =&gt; array('slug' =&gt; 'driver'),
          'capability_type'     =&gt; 'page',
      );
      register_post_type( 'drivers', $args );
  }
  // Hook into the 'init' action
  add_action( 'init', 'drivers_post_type', 0 );
  
  // Little function to return a custom field value
  function driverMB_get_custom_field( $value ) {
    global $post;
  
      $custom_field = get_post_meta( $post-&gt;ID, $value, true );
      if ( !empty( $custom_field ) )
        return is_array( $custom_field ) ? stripslashes_deep( $custom_field ) : stripslashes( wp_kses_decode_entities( $custom_field ) );
  
      return false;
  }
  
  // Register the Metabox
  function driverMB_add_custom_meta_box() {
      add_meta_box( 
          'driverMB-meta-box', 
          __( 'driver Info', 'textdomain' ), 
          'driverMB_meta_box_output', 
          'drivers', 
          'normal', 
          'default' 
      );
  }
  add_action( 'add_meta_boxes', 'driverMB_add_custom_meta_box' );
  
  // Output the Metabox
  function driverMB_meta_box_output( $post ) {
    // create a nonce field
    wp_nonce_field( 'my_driverMB_meta_box_nonce', 'driverMB_meta_box_nonce' ); ?&gt;
  
      &lt;p&gt;
          &lt;label&gt;&lt;b&gt;ID&lt;/b&gt;&lt;/label&gt;
          &lt;label&gt;&lt;?php echo get_the_ID() ?&gt;&lt;/label&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label&gt;&lt;b&gt;Username&lt;/b&gt;&lt;/label&gt;
          &lt;input type="text" placeholder="Username" name="username" id="username" value="&lt;?php echo driverMB_get_custom_field( 'username' ); ?&gt;" style="width:100%;" /&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/label&gt;
          &lt;input type="password" placeholder="Password" name="password" id="password" value="&lt;?php echo driverMB_get_custom_field( 'password' ); ?&gt;" style="width:100%;" /&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label&gt;&lt;b&gt;Email&lt;/b&gt;&lt;/label&gt;
          &lt;input type="text" placeholder="Email" name="email" id="email" value="&lt;?php echo driverMB_get_custom_field( 'email' ); ?&gt;" style="width:100%;" /&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label&gt;&lt;b&gt;Phone Number&lt;/b&gt;&lt;/label&gt;
          &lt;input type="text" placeholder="Ext : 088216192560" name="phone" id="phone" value="&lt;?php echo driverMB_get_custom_field( 'phone' ); ?&gt;" style="width:100%;" /&gt;
      &lt;/p&gt;
  
    &lt;?php
  }
  
  // Save the Metabox values
  function driverMB_meta_box_save( $post_id ) {
    // Stop the script when doing autosave
    if( defined( 'DOING_AUTOSAVE' ) &amp;&amp; DOING_AUTOSAVE ) return;
  
    // Verify the nonce. If insn't there, stop the script
    if( !isset( $_POST['driverMB_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['driverMB_meta_box_nonce'], 'my_driverMB_meta_box_nonce' ) ) return;
  
    // Stop the script if the user does not have edit permissions
    if( !current_user_can( 'edit_post' ) ) return;
  
      // Save the textfield
    if( isset( $_POST['username'] ) )
      update_post_meta( $post_id, 'username', esc_attr( $_POST['username'] ) );
    if( isset( $_POST['password'] ) )
      update_post_meta( $post_id, 'password', esc_attr( $_POST['password'] ) );
    if( isset( $_POST['email'] ) )
      update_post_meta( $post_id, 'email', esc_attr( $_POST['email'] ) );
    if( isset( $_POST['phone'] ) )
      update_post_meta( $post_id, 'phone', esc_attr( $_POST['phone'] ) );
  }
  add_action( 'save_post', 'driverMB_meta_box_save' );
  </code></pre>
  
  
  
  <p>i dont know how to create it as api. my friend told me to create if url equals then perform action function, but i dont know how ?</p>
  
  <p>Does someone tell me or help me to create an api for wordpress ?</p>