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>".$wpdb->postmeta."</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
The topic ‘Function lookup using node tag’ is closed to new replies.