Title: Function lookup using node tag
Last modified: January 25, 2017

---

# Function lookup using node tag

 *  Resolved [W3bLink](https://wordpress.org/support/users/w3blink/)
 * (@w3blink)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/function-lookup-using-node-tag/)
 * Hi,
 * I am trying to replace a node value that is placed into a custom field by using
   the node value to look up a post ID and then replace the node value with that
   post id.
 * I don’t mean the post ID for what WP ALL Import will create, I know that hasn’t
   been created yet. It’s looking up another custom post that this will relate to.
   I’m importing coupons and these coupons need to be linked to stores that are 
   already created.
 * I have a function that is working when manually entering what the node value 
   would be; but am struggling getting it to work with WP All Import.
 * I have the below code in my functions.php file. This function checks the post
   meta key value and looks up the post ID it relates to. Each post has a unique
   meta key value.
 *     ```
       function get_post_id_by_meta_key_and_value($key, $value) {
       	global $wpdb;
       	$meta = $wpdb->get_results("SELECT * FROM <code>&quot;.$wpdb->postmeta.&quot;</code> WHERE meta_key='".$wpdb->escape($key)."' AND meta_value='".$wpdb->escape($value)."'");
       	if (is_array($meta) && !empty($meta) && isset($meta[0])) {
       		$meta = $meta[0];
       		}	
       	if (is_object($meta)) {
       		return $meta->post_id;
       		}
       	else {
       		return false;
       		}
       	}
       }
       ```
   
 * I then have this code in my functions.php file to input the variables into the
   above function, and it works by manually entering the value:
 *     ```
       function aw_offer_store($awStoreID) {
           $awStoreID = get_post_id_by_meta_key_and_value('aw_store_name', 'Qatar Airways (Global)');
           return $awStoreID;
       }
       ```
   
 * But when I try using the node tag it doesn’t work:
 *     ```
       function aw_offer_store($awStoreID) {
           $awStoreID = get_post_id_by_meta_key_and_value('aw_store_name', '{advertiser[1]}');
           return $awStoreID;
       }
       ```
   
 * I have the below code in my custom field inside of WP All Import:
 * `[aw_offer_store({advertiser[1]})]`
 * It looks like the value of the the node tag (example: `{advertiser[1]}`) isn’t
   being pulled into the function. I’ve even tried declaring the node tag as a variable
   and putting that into the function, but that isn’t working.
 * I hope I have explained what I am trying to achieve clearly and you can help.
 * Thank you,
    Elliot

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

 *  Plugin Author [WP All Import](https://wordpress.org/support/users/wpallimport/)
 * (@wpallimport)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/function-lookup-using-node-tag/#post-8703694)
 * Hey [@w3blink](https://wordpress.org/support/users/w3blink/)
 * The node value is being passed to the $awStoreID variable in your function, so
   this code would work:
 *     ```
       function aw_offer_store($awStoreID) {
           $awStoreID = get_post_id_by_meta_key_and_value('aw_store_name', $awStoreID);
           return $awStoreID;
       }
       ```
   
 *  Thread Starter [W3bLink](https://wordpress.org/support/users/w3blink/)
 * (@w3blink)
 * [9 years, 4 months ago](https://wordpress.org/support/topic/function-lookup-using-node-tag/#post-8706448)
 * Hi,
 * Yes I figured that out late last night, silly mistake. Thank you for your help.

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

The topic ‘Function lookup using node tag’ 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/)

## Tags

 * [function](https://wordpress.org/support/topic-tag/function/)

 * 2 replies
 * 2 participants
 * Last reply from: [W3bLink](https://wordpress.org/support/users/w3blink/)
 * Last activity: [9 years, 4 months ago](https://wordpress.org/support/topic/function-lookup-using-node-tag/#post-8706448)
 * Status: resolved