Jump to content

Dynamic field type on saving a page


Christian
 Share

Recommended Posts

Hi! I have a problem dealing with dynamic saving of content on API. I never encounter any problem when I save a page when static so there is no problem on fetching a new data.

Dynamic field name that is not working.

foreach( $page->fields as $field ) {
  if( ! in_array($field->type, $ignore_field_type) ) {
    $field_name = $field->name;
    $revise_page->$field_name = $page->get($field->name);
  }
}

Static field name that is working.

$revise_page->site_metadata = $page->get("site_metadata");
$revise_page->body          = $page->get("body");
Link to comment
Share on other sites

Fixed. Just have to add curly braces.
 

foreach( $page->fields as $field ) {
  if( ! in_array($field->type, $ignore_field_type) ) {
    $field_name = $field->name;
    $revise_page->{$field_name} = $page->get($field->name);
  }
}
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...