Automate service schedule display on CPT service page

Hi, I have linked my 'services' to a custom post type called 'Equipment' via the Service Description Post Type add-on. It's great, but only works in one direction, associating the CPT with the service. I'd like to use it the other way 'round and automatically display which service is associated on the CPT page.
I know I can do this via the shortcode [app_schedule service="ID_#"] and that works great - but it's not very intuitive for admins to have to search through 50+ services for an ID number to manually insert in the Equipment CPT's shortcode.

I'd love to provide a dropdown or association of some sort in the Equipment CPT's control panel page showing all available Services by title. I know this would be very easy if the services were CPTs themselves (I'm using Advanced Custom Fields), but they're not.

So - is there a way to accomplish this do you know? And/or do you know if there are any plans to create an add-on or convert Appointments+ to use CPTs?


  • Vaughan
    • Support/SLS MockingJay

    Hi @Michelle,

    I'm not sure this would be possible out the box without some custom code to create a custom query or something. With regards to the feature itself, I can certainly ask the developer for some feedback on this & will also add this to the feature requests for the developer to look into.

    Hope this helps

  • Vladislav
    • Dead Eye Dev


    Fortunately, this shouldn't be very difficult. This bit of code will show the monthly schedule for the service on their selected description page/CPT, when displayed "standalone", so to speak:

    function my_app_append_service_workhours_to_description_page ($body) {
    	if (!class_exists('App_PostTypes_ServiceDescription')) return $body; // Make sure the add-on is active
    	global $post, $appointments, $wpdb;
    	$description_post_type = !empty($appointments->options['service_description_post_type'])
    		? $appointments->options['service_description_post_type']
    		: App_PostTypes_ServiceDescription::POST_TYPE
    	if (!is_singular($description_post_type)) return $body; // Make sure we're on single page for appropriate post type
    	$service_id = $wpdb->get_var(
    		$wpdb->prepare("SELECT ID FROM {$appointments->services_table} WHERE page=%d LIMIT 1", (int)$post->ID)
    	if (empty($service_id)) return $body; // Make sure we have a service ID to show
    	return $body .
    		do_shortcode("[app_monthly_schedule service='{$service_id}' title='Working hours' logged='']")
    if (!is_admin()) add_filter('the_content', 'my_app_append_service_workhours_to_description_page');

    I have added some comments to explain the key points. As you can see, rather than complicate things further with direct code access, we just add the schedule with the do_shortcode() call and let the shortcode do the heavy lifting for us. You can, of course, use a different shortcode there, and any other supported shortcode attribute there - the only concern there is quoting, so we don't break the PHP string and thus break the code. I hope this helps.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.