Hooking into WordPress Business Directory

Today I was working on a site that uses the WordPress Business Directory Plugin (WPBDP). I needed to link a phone number field for mobile devices but couldn’t find anything useful in the plugin’s documentation… so I did what I always do and dug through the plugin source.

I found several useful WP hooks, and was able to write a quick function to do what I wanted. The code below goes into a theme’s functions.php file or a simple plugin.

This assumes that the ID of the phone field is 6. The field’s ID can be found by editing the field and looking for the ID in the URL.

Screen Shot 2014-12-08 at 3.43.50 PM

2 responses to “Hooking into WordPress Business Directory”

  1. J In the Wild Avatar
    J In the Wild

    The only problem with that is that you are hard coding variables, what you should have instead create a custom fields area in the admin to extend the functionality of the business directory script. Now if that field changes you are going to have to go back to the source code and change it, which might be okay if you are the only person to ever touch the code or work on the site, but if someone else takes it over they are going to have a headache and want to stab you with a frozen banana. — jmtc


    1. You are correct, the ID of the field is hardcoded, but I disagree with your other arguments.

      That ID should never change. The phone number field is a default field that comes with the plugin. This ID will only change if you manually delete the field and recreate it, and why would you want to do that?

      However if you’re really worried about the ID changing, I would recommend commenting that block of code and explaining what it does and how to update it. It seems like a waste of cycles and time to run an extra query, but to each his/her own.

      Finally, I prefer frozen bananas in smoothies versus inserted into my abdomen.


Leave a Reply

Your email address will not be published. Required fields are marked *