Title: Overwriting Attribute Values
Last modified: December 18, 2020

---

# Overwriting Attribute Values

 *  Resolved [ilyapokrov](https://wordpress.org/support/users/ilyapokrov/)
 * (@ilyapokrov)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/overwriting-attribute-values/)
 * I very much ask you to give me a tip with the formula, since I am not very strong
   in this.
 * As a varied example, let’s say I have parameters like this:
 * <param name=”gender”>Male</param>
    <param name=”gender”>Women</param> <param 
   name=”gender”>Naughty children</param> <param name=”gender”>dogs and cats</param
   >
 * I use this formula to write attributes:
 * `[my_map_data_Probnik({param[@name="gender"]})]`
 *     ```
       function my_map_data_Probnik( $data ) {
           $map = array(
       		'Male' => 'For Male',
       		'Women' => 'For women',
           );
           return ( array_key_exists( $data, $map ) ) ? $map[ $data ] : $data;
       }
       ```
   
 * And here’s my question:
 * How to rewrite this formula to do the following:
    If parameter = ‘Male’, then
   write as ‘For Male’. If parameter = ‘Women’, then write as ‘For women’. If the
   parameter contains the word ‘Children’, then write it as ‘For children’. If the
   parameter is different, then do not write anything.
 * I looked at your instructions but couldn’t find a similar example.
    I very much
   ask you to help me, as I cannot write the code on my own.
 * Thank you in advance!

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/overwriting-attribute-values/#post-13812732)
 * Hi [@ilyapokrov](https://wordpress.org/support/users/ilyapokrov/),
 * > How to rewrite this formula to do the following:
   >  If parameter = ‘Male’, then
   > write as ‘For Male’. If parameter = ‘Women’, then write as ‘For women’. If 
   > the parameter contains the word ‘Children’, then write it as ‘For children’.
   > If the parameter is different, then do not write anything.
 * You’d have to use if statements to do that: [https://www.php.net/manual/en/control-structures.if.php](https://www.php.net/manual/en/control-structures.if.php).
 * Unfortunately, I do not have an example snippet that does exactly what you describe,
   but we have a lot of code examples here that might help: [https://www.wpallimport.com/documentation/developers/code-snippets/](https://www.wpallimport.com/documentation/developers/code-snippets/).
 *  Thread Starter [ilyapokrov](https://wordpress.org/support/users/ilyapokrov/)
 * (@ilyapokrov)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/overwriting-attribute-values/#post-13832213)
 * [@wpallimport](https://wordpress.org/support/users/wpallimport/),
    I coped with
   the task with code like this:
 *     ```
       function my_map_data_Probnik( $data ) {
           $map = array(
       		'Male' => 'For Male',
       		'Women' => 'For women',
   
           );
       	if (array_key_exists($data, $map)) {
           return $map[$data];
       }
       	if (mb_strpos($data, 'children') !== false) {
           return 'for children';
       }
       	if (mb_strpos($data, 'toddlers') !== false) {
           return 'for babies';
       }
       	return null;
           return ( array_key_exists( $data, $map ) ) ? $map[ $data ] : $data;
       }
       ```
   
 * I am sharing this code with you, suddenly it will be useful to someone.
    But 
   there is a nuance. I don’t know if you can help me with this or not. For the 
   speed of the site, I connected a VPS cloud hosting. I noticed that when I use
   this feature my hosting often drops the connection and the site gets an error–
   No database access. The hosting says that the problem is in the site scripts –
   they need to be optimized. RAM of 1 GB is not enough for this job. I specifically
   checked on a YML file, which contains only 5 products. And I don’t think this
   operation wastes more than 1 GB of RAM.
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/overwriting-attribute-values/#post-13849710)
 * Hi [@ilyapokrov](https://wordpress.org/support/users/ilyapokrov/),
 * > I noticed that when I use this feature my hosting often drops the connection
   > and the site gets an error – No database access.
 * By “this feature”, do you mean when you run an import? If so, imports can be 
   very resource-intensive and your server needs to be able to handle the amount,
   and type, of data that you’re importing. This guide will help you optimize the
   import and use as little resources as possible: [https://gist.github.com/trey8611/72fec5969651d5272fcb85f99b09b8bb](https://gist.github.com/trey8611/72fec5969651d5272fcb85f99b09b8bb).
 * > I specifically checked on a YML file, which contains only 5 products. And I
   > don’t think this operation wastes more than 1 GB of RAM.
 * You wouldn’t think so, but it really depends on the data that’s being imported
   and what’s happening in the background. For example, if you try to import 500
   taxonomy terms and 50 images per-record, it’s likely going to take up a lot of
   resources. Also, keep in mind that your theme and other plugins could be doing
   a lot of heavy operations in the background that you’re not even aware of (these
   could be per-image imported, per-term, per-record, etc).
 * If the guide I sent you above doesn’t help narrow down what’s causing the resource
   usage, you’ll need to work with a sysadmin to figure out exactly what’s going
   on and exactly how your server needs to be configured to handle it.
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [5 years, 5 months ago](https://wordpress.org/support/topic/overwriting-attribute-values/#post-13873838)
 * Hi [@ilyapokrov](https://wordpress.org/support/users/ilyapokrov/),
 * I’m marking this as resolved since we haven’t heard back in a while. You can 
   follow up in this thread if you have more questions.
 * Anyone else reading this, please open a new topic.

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

The topic ‘Overwriting Attribute Values’ is closed to new replies.

 * ![](https://ps.w.org/wp-all-import/assets/icon-256x256.png?rev=2570179)
 * [WP All Import – Drag & Drop Import for CSV, XML, Excel & Google Sheets](https://wordpress.org/plugins/wp-all-import/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-all-import/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-all-import/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-all-import/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-all-import/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-all-import/reviews/)

 * 4 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [5 years, 5 months ago](https://wordpress.org/support/topic/overwriting-attribute-values/#post-13873838)
 * Status: resolved