It should already be ignoring the other items.
Also, looking at your line for BuyMerchantItem - the wiki page doesn't say it returns a value, so it will always be false I suspect. This could be the cause of your problem
https://warcraft.wiki.gg/wiki/API_BuyMerchantItem
Lua Code:
local function BuyItemsFromVendor(vendorName)
-- Create a table of items for this vendor's name
local vendor = vendors[vendorName]
-- No items ? Then don't bother with the rest of the work
if not vendor then return end
local numItems = GetMerchantNumItems()
for i = numItems, 1, -1 do
local name = GetMerchantItemInfo(i)
-- Is this item in the list of items for this vendor we want to buy ?
if vendor[name] then
local success = BuyMerchantItem(i)
if success then
PrintMessage("Purchased: " .. name)
else
PrintMessage("Failed to purchase: " .. name)
end
end
end
end