Your directory can use Custom Post Types to create distinct listings with different fields. This is an important tool if you want your directory to be diverse, to include different types of listings. With the addon you can create and manage new custom post types. Get the Custom Post Types add-on for GeoDirectory and get started.
See more here: https://wpgeodirectory.com/downloads/custom-post-types/
Check to be sure you have the following plugins installed before you get started.
To Link one CPT to another, visit the Custom Post Type Settings Custom Fields tab.
CPT link fields are near the bottom of the page. Choose a link type and click to add to your CPT listing form.
A view of the complete custom fields tab, with the Link fields near the bottom left.
CPT-Custom-Field-Complete.png">CPT-Custom-Field-Complete.png" alt="" width="705" height="1155" class="alignnone size-full wp-image-205" srcset="https://wpgd-jzgngzymm1v50s3e3fqotwtenpjxuqsmvkua.netdna-ssl.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Custom-Field-Complete.png 705w, https://wpgeodirectory.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Custom-Field-Complete-183x300.png 183w, https://wpgeodirectory.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Custom-Field-Complete-625x1024.png 625w" sizes="(max-width: 705px) 100vw, 705px" />
Link CPT Field Settings
Adjust field settings as desired. If you want to allow a link to more than one post, then make sure to set the value for Max to more than 1.
CPT-Link-Places-Settings.png">CPT-Link-Places-Settings.png" alt="" width="542" height="947" class="alignnone size-full wp-image-195" srcset="https://wpgd-jzgngzymm1v50s3e3fqotwtenpjxuqsmvkua.netdna-ssl.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Link-Places-Settings.png 542w, https://wpgeodirectory.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Link-Places-Settings-172x300.png 172w" sizes="(max-width: 542px) 100vw, 542px" />
You can link ‘from’ hospitals to Doctors. Each such link would allow the hospital to link to one or more doctors.
You can link ‘from’ Doctors to hospitals. Each such link would allow a doctor listing to link to one or more hospitals.
Use the custom field ‘linked from’ in the Hospital Settings – Custom Fields – Custom Fields
Link from Hospital to the Doctor
Link from Doctor to Hospital
The Custom Post Types addon enables a new design element called gd_linked_posts. This element is available as a widget, block, or shortcode.
Use the element to display linked posts.
CPT-Widget-Basic.png">CPT-Widget-Basic.png" alt="" width="286" height="397" class="alignnone size-full wp-image-201" srcset="https://wpgd-jzgngzymm1v50s3e3fqotwtenpjxuqsmvkua.netdna-ssl.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Widget-Basic.png 286w, https://wpgeodirectory.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Widget-Basic-216x300.png 216w" sizes="(max-width: 286px) 100vw, 286px" />
CPT-Widget-Advanced.png">CPT-Widget-Advanced.png" alt="" width="285" height="616" class="alignnone size-full wp-image-200" srcset="https://wpgd-jzgngzymm1v50s3e3fqotwtenpjxuqsmvkua.netdna-ssl.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Widget-Advanced.png 285w, https://wpgeodirectory.com/docs-v2/wp-content/uploads/sites/23/2018/08/CPT-Widget-Advanced-139x300.png 139w" sizes="(max-width: 285px) 100vw, 285px" />
Example of the gd_linked_posts shortcode:
[gd_linked_posts title="Custom Title" id="-4" link_type="to" post_type="gd_hospital" sort_by="az" title_tag="h3" layout="list" post_limit="5"]
Shortcode builder options:
CPT-Linked-Posts.png">CPT-Linked-Posts.png" alt="" width="686" height="592" class="alignnone size-full wp-image-204" srcset="https://wpgd-jzgngzymm1v50s3e3fqotwtenpjxuqsmvkua.netdna-ssl.com/docs-v2/wp-content/uploads/sites/23/2018/08/Shortcode-Builder-CPT-Linked-Posts.png 686w, https://wpgeodirectory.com/docs-v2/wp-content/uploads/sites/23/2018/08/Shortcode-Builder-CPT-Linked-Posts-300x259.png 300w" sizes="(max-width: 686px) 100vw, 686px" />
It is possible to sort gd_linked_posts shortcode (only) by event date, but first make sure the sorting options are set to sort by date. Visit:
Events (CPT) – Settings – Sorting (Tab) – Event Date. Choose event date and use as the primary sort
Then in your shortcode, substitute
For more information about using CSS and PHP customization snippets please see our doc about customizing.
Snippets from the forum
Hide CPT B fromPost Type Select on Directory Map on Archive for CPT A. See this topic.
Get support on our forum, find out more here: https://wpgeodirectory.com/docs-v2/geodirectory/support/
Can the Title, Description and Address be set to autocomplete and pull the information from the linked post?
Not at this time because each post type can be linked to multiple other posts.
Here is an example of how that can be done for a CPT called gd_schools in a snippet.
GD Linked Posts
When you add GD Linked Posts custom field to your Tabs UI there isn’t an option to adjust the layout.
To adjust the layout you will need to add a shortcode custom field in the tabsUI and use a shortcode in that shortcode field with the layout or other options you want.
In this example we want to show linked events as a list. Events are linked TO the Places, but we are adding the list of events ON the places detail tabs, so for our shortcode, we want to show listings linked “From” the Events post type. And of course we need to add that layout=”list” to make it the way we want.
Step by step:
- Open the places settings and click the Tabs (tab)
- Add a shortcode custom field
- Use a shortcode builder to create the GD Linked Posts shortcode that you want ex.
[gd_linked_posts link_type="from" post_type="gd_event" sort_by="az" title_tag="h3" layout="list" post_limit="1000"]
- Add the shortcode to the shortcode field
- Name your tab and choose and icon and save
- Check the detail page to see the new layout in the new tab
- Remvoe the old field from the tabs if you don’t want it anymore
- Bob’s your uncle
Multiple Links to the Same Post Type
With the Custom Post Types Addon installed it is possible to create one (1) link from each Custom Post Type to any other post type (including itself).
Though a project may benefit from a second (or N additional) link field, perhaps for a different kind of relationship, this is would be a customization that would require custom code and falls outside of support.
– In V1 it was possible to auto-fill the basic business info when adding a link event to a place. This is no longer possible in V2 because the link field supports multiple linked posts.