Title: Conditional Statements with custom function
Last modified: October 30, 2016

---

# Conditional Statements with custom function

 *  Resolved [ckitso](https://wordpress.org/support/users/ckitso/)
 * (@ckitso)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/conditional-statements-with-custom-function/)
 * Hi all,
 * I am trying to create a conditional statement for a json file I receive form 
   a Dealer Management system to sync the data between the site and the system.
 * To give a background the site has 6 taxonomies for Makes of Vehicle, 5 of which
   are branded. They are Alfa, Jeep, Suzuki, Fiat, Fiat Pro and Other-Makes. The
   Json file i receive however doesn’t quite match the taxonomies in that it doesn’t
   group the none branded makes into Other-makes instead it uses their actual make
   for example, Nissan, Toyota etc. The second problem is that the Fiat Vehicles
   are all grouped under Fiat instead of being split between their normal and professional
   ranges.
 * **So what I need to do is create conditional statement for the make taxonomy 
   that **
 * 1) Checks if the entry is an Alfa, Jeep, Suzuki or Fiat if it is then it gets
   the value from the Json file otherwise it gets given the value Other-Make.
 * 2) Checks to see if the vehicle is a Fiat or Fiat Pro, the only way to do this
   is to check if the vehicle model belongs to the Fiat Pro range and if it does
   then it gets the value Fiat Pro otherwise it gets the value Fiat.
 * **What I have done so far:**
 * 1) I have managed to create a function to check the make and assign Other-Makes
   like so :
 *     ```
       function ae_make($Importmake) {
       if  (($Importmake == "ALFA ROMEO") or ($Importmake == "JEEP") or ($Importmake == "SUZUKI") or ($Importmake == "FIAT")) :
           $x = $Importmake;
       else: 
          $x = "Other-makes";
       endif;
       return $x;
       }
       ```
   
 * and in the wp-all-import category field I have used this [ae_make({make[1]})]
   which works perfectly
 * 2) Trying to check if the vehicle is Fiat or Fiat Pro is proving tricky. I have
   tried creating a second function that checks the model variable and returns a
   value. On its own it works.
 * However I am not sure how to check both conditions are meet within the category
   field. I tried using the inbuilt conditional statements in WP all import like
   this… [IF({ae_model({model[1]})[contains(.,’Fiat Pro’)]})]FIAT PRO [ELSE][ae_make({
   make[1]})][ENDIF]
    But the syntax is wrong and I am not even sure if it is possible
   to go this route.
 * 3) I have also tried creating an advanced condition custom function which accepts
   two variable inputs and returns one value using this call [ae_make({make[1]},{
   model[1]})]
    I am not sure if that is even allowed or if the code below is correct.
 *     ```
       function ae_make($Importmodel, $Importmake) {
   
       if  (($Importmake == "ALFA ROMEO") or ($Importmake == "JEEP") or ($Importmake == "SUZUKI") or ($Importmake == "FIAT")) :
           $x = $Importmake;
       elseif ($Importmake == "FIAT" && ($Importmodel == "FULLBACK" || $Importmodel == "FIORINO" || $Importmodel == "DOBLO CARGO" || $Importmodel == "DOBLO PANORAMA" || $Importmodel == "DUCATO")):
          $x = "Fiat-Pro";
       else: 
          $x = "Other-makes";
       endif;
   
       return $x;
       }
       ```
   
 * If you could possibly point me in the right direction that would be great. Either
   using a custom function or if the inbuilt If conditionals allow for multiple 
   conditions that could also work. Something like this perhaps?
 * [IF({model[contains(.,’FULLBACK’) or (.,’DOBLO PANORAMA’) or (.,’DOBLO CARGO’)]})]
   
   Fiat Pro [ELSE] [ae_make({make[1]})]
 * Any assistance would be appreciated.
    Thanks

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

 *  Thread Starter [ckitso](https://wordpress.org/support/users/ckitso/)
 * (@ckitso)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/conditional-statements-with-custom-function/#post-8373950)
 * It would appear that there was an error in my conditional logic.
 * This method seems to work in adding the correct make during the import :
 * Using the custom PHP function in my function.php listed below. Along with the[
   ae_make({make[1]}, {model[1]})] in my Makes Category field in Wp-All-Import.
 *     ```
       // WP ALL IMPORT CONDTIONAL IMPORT
   
       function ae_make($Importmake, $Importmodel) {
   
       if  (($Importmake == "ALFA ROMEO") or ($Importmake == "JEEP") or ($Importmake == "SUZUKI")):
           $x = $Importmake;
       elseif ($Importmake == "FIAT" && ($Importmodel == "FULLBACK" || $Importmodel == "FIORINO" || $Importmodel == "DOBLO CARGO" || $Importmodel == "DOBLO PANORAMA" || $Importmodel == "DUCATO")):
          $x = "Fiat-Pro";
       elseif($Importmake == "FIAT"):
          $x = $Importmake;;
       else: 
          $x = "Other-makes"; 
       endif;
   
       return $x;
       }
       ```
   
 * I’m still not sure if this is the best method though so if their is a better 
   method please let me know.
 * Thanks
 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [9 years, 7 months ago](https://wordpress.org/support/topic/conditional-statements-with-custom-function/#post-8388111)
 * Hi ckitso.
 * When it comes to conditional logic such as this, we typically suggest using custom
   PHP functions for more flexibility and power. So, I think your custom function
   is the best way to tackle this.

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

The topic ‘Conditional Statements with custom function’ 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/)

 * 2 replies
 * 2 participants
 * Last reply from: [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * Last activity: [9 years, 7 months ago](https://wordpress.org/support/topic/conditional-statements-with-custom-function/#post-8388111)
 * Status: resolved