Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions v3/lib/class-acf-to-rest-api-acf-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get_id( $object ) {
if ( 'option' == $this->type ) {
$this->id = sanitize_title( $this->id );
} else {
$this->id = absint( $this->id );
$this->id = preg_replace("/[^0-9]/", "", $this->id);
}

return $this->format_id();
Expand All @@ -74,7 +74,7 @@ public function get_id( $object ) {
public function get_fields( $request ) {
$data = array();
$field = null;

if ( $request instanceof WP_REST_Request ) {
$field = $request->get_param( 'field' );
}
Expand Down Expand Up @@ -130,7 +130,16 @@ public function get_field_objects( $id ) {
$fields_tmp = array();

if ( function_exists( 'acf_get_field_groups' ) && function_exists( 'acf_get_fields' ) && function_exists( 'acf_extract_var' ) ) {
$field_groups = acf_get_field_groups( array( 'post_id' => $id ) );

if ( strpos( $id, 'user_' ) !== false ) {
$filter = array( 'user_id' => str_replace( 'user_', '', $id ) );
} elseif ( strpos( $id, 'taxonomy_' ) !== false ) {
$filter = array( 'taxonomy' => str_replace( 'taxonomy_', '', $id ) );
} else {
$filter = array( 'post_id' => $id );
}

$field_groups = acf_get_field_groups( $filter );

if ( is_array( $field_groups ) && ! empty( $field_groups ) ) {
foreach ( $field_groups as $field_group ) {
Expand Down