get_service_name in page template


I'm looking to display the service name (based on the ID) on the front end in a page template. Looking into the plugin code there are functions, such as get_service() and get_service_name() which each take the ID.

These don't work on within the WP theme. Can we somehow get hold of the service name based on the known ID within theme files?

Many thanks,

p.s. Can I be cheeky and ask for help on this thread too,

  • scdwb
    • Design Lord, Child of Thor

    Hi all,

    I helped myself with this issue and created a new shortcode called shortcode_get_service_name, which gets the service name via it's ID.

    function shortcode_get_service_name( $atts ) {
    		global $wpdb;
    		extract( shortcode_atts( array(
    		'id'		=> '1'
    		), $atts ) );
    		$services = $this->get_service_name($id);
    		return $services;

    Within your theme files you can call the shortcode within php tags using:

    <?php echo do_shortcode("[app_service_name id='1']"); ?>

    I'm taking advantage of the app_service_id parameter used when selecting a service from the dropdown menu and I'm automatically adding the $GET value to the ID parameter of the shortcode:

    <?php $service_id = $_GET['app_service_id']; echo do_shortcode("[app_service_name id='$service_id']"); ?>

    Ideally I would add this shortcode via my themes functions.php to avoid changing the plugin's hard code so if anyone can help me do this that would be perfect.


  • PC
    • WPMU DEV Initiate

    Hiya @scdwb

    Greetings and thanks for posting on the forums and also for sharing the nice piece of code for which I am sending a few points your way.

    I tried to look around and mess up with the code myself but could not get a proper way to get this implemented.

    I am going to call our lead developer @Hakan so that he can provide his expert advice on this one.

    Please note that as he is working on a major plugin release, it might take a while to get a response from him but I will keep a track and will followup on this one.

    Sales &Support

  • Hakan
    • The Incredible Smush


    You can use any functions (methods) of A+ like this:

    function my_function( $service_id, $worker_id, $whatever ) {
    global $appointments;
    $service_name = $appointments->get_service_name( $service_id );
    $worker_name = $appointments->get_worker_name( $worker_id );
    $worker_email = $appointments->get_worker_email( $worker_id );
    // etc...

    If you are not using a hook and thus $service_id, $worker_id are not transferred to the function as parameters, you can read them like this:

    global $appointments;
    $service_id= $appointments->service;
    $worker_id= $appointments->worker;

    This will give you currently selected service and provider if there is one. If not, you will get the first service and no worker (0: No preference-general staff).

    @Steven, your function will not work because a) $this is not defined there b) You have to declare a shortcode.

    On the other hand, why would you need a shortcode to be used in a page template in the first place? Shortcodes are intended for WP editor, not for php files. Well, there is a do_shortcode function, but it is for using an already existing shortcode. Normally you don't need a shortcode for templates. In your case, just use this:

    // This will print the current service name, regardless of where you use it.
    global $appointments;
    echo $appointments->get_service_name( $appointments->service );

    As short as like that, but for safety you can check if $appointments is existing as an object (A+ might have been deactivated).

    I am sorry but I must say, I see that you are trying to make progress by getting help from here, but you need to have more background about php classes/objects and WP functions. and are gigantic resources. They are very well documented. Please use them. You can start here:


  • PC
    • WPMU DEV Initiate


    Greetings and thanks for being a great community member.

    We haven't heard from you on this one for long and I am doing a regular followup to see if there is still something we can assist you on this thread.

    Just to manage the support issues more efficiently, I am marking this thread as resolved for now however this is not being done to avoid your questions in any ways.

    Please feel free to mark this is "Not resolved" in case you have further questions and we would be back on it.

    Thanks a lot for being with WPMU DEV.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.