Title: setAttributes doesn&#8217;t save attributes
Last modified: March 16, 2020

---

# setAttributes doesn’t save attributes

 *  [creativiii](https://wordpress.org/support/users/creativiii/)
 * (@creativiii)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/)
 * Hi all,
 * I’m fairly new to working with Blocks. I have previously managed to make a plugin
   that changed my post’s meta values, however I’m now trying to make something 
   a lot simpler and it’s just refusing to update the data in the backend.
 * You can find source code for my block [here](https://github.com/creativiii/ironeko-featured-content/blob/master/src/index.js).
   It simply adds a toggle to set a meta value to false or true.
 * While the value to my attribute seems to change after calling:
    `setAttributes({
   featured: value } );`
 * If I save my post and check the rest api, the value actually won’t have changed.
 * I have absolutely no clue why this isn’t working. Is there anything wrong with
   the code?
    -  This topic was modified 6 years, 2 months ago by [creativiii](https://wordpress.org/support/users/creativiii/).
    -  This topic was modified 6 years, 2 months ago by [creativiii](https://wordpress.org/support/users/creativiii/).

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Michael Levy](https://wordpress.org/support/users/eruna_msl/)
 * (@eruna_msl)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12548979)
 * It looks like the problem is the mix of setState and setAttributes.
 * Take a look at this example:
 *     ```
       edit({ attributes, setAttributes }) {
   
         function onChangeCheckboxField( ) {
           let toggledValue=(attributes.isNew===true)?false:true;
           setAttributes( { isNew: toggledValue } );
         }
   
         return (
           <div className="container de_title">
             <PlainText
               onChange={ content => setAttributes( { price: content } ) }
               value={ attributes.price }
               placeholder="price"
               className="price"
             />
           </div>
         );
       },
       ```
   
 *  Thread Starter [creativiii](https://wordpress.org/support/users/creativiii/)
 * (@creativiii)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12549101)
 * That’s also what I thought, so I changed it to just use Attributes rather than
   a mix, but the problem is still the same.
 * I’ve updated the github.
 *  [Michael Levy](https://wordpress.org/support/users/eruna_msl/)
 * (@eruna_msl)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12553255)
 * `<FeaturedRadio featured={attributes.featured}/>`
 * Do you need to pass `attributes.featured` since it should already be accessible
   to the function?
 *  Thread Starter [creativiii](https://wordpress.org/support/users/creativiii/)
 * (@creativiii)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12553970)
 * Updated the Github, that wasn’t the problem either
 *  Thread Starter [creativiii](https://wordpress.org/support/users/creativiii/)
 * (@creativiii)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12554186)
 * I figured it out. It seems that at some point I added another custom block and
   used the same name for it.
 *     ```
           wp_enqueue_script(
               'palette-script', // this was already used
               plugins_url( 'build/index.js', __FILE__ ),
               array( 'wp-blocks', 'wp-element', 'wp-components' )
           );
       ```
   
 * So even though they were in completely different files and my Block didn’t give
   me any errors, it was actually conflicting with the way it was working.
 *  Thread Starter [creativiii](https://wordpress.org/support/users/creativiii/)
 * (@creativiii)
 * [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12558715)
 * Upon second inspection I can set the attributes to true, but I can’t set it to
   false after.
 * That’s really strange and doesn’t make a whole lot of sense to me.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘setAttributes doesn’t save attributes’ is closed to new replies.

 * ![](https://ps.w.org/gutenberg/assets/icon-256x256.jpg?rev=1776042)
 * [Gutenberg](https://wordpress.org/plugins/gutenberg/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gutenberg/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gutenberg/)
 * [Active Topics](https://wordpress.org/support/plugin/gutenberg/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gutenberg/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gutenberg/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [creativiii](https://wordpress.org/support/users/creativiii/)
 * Last activity: [6 years, 2 months ago](https://wordpress.org/support/topic/setattributes-doesnt-save-attributes/#post-12558715)
 * Status: not resolved