Home Forums General Issues CPT that generates subdomains with fields from other CPT


CPT that generates subdomains with fields from other CPT

  • Hey everyone. I couldn’t find anything out there about this so thought I’d give these forums a shot!

    I have a CPT called “Properties” with several fields and a beautiful, detailed single listing page for each property on my site.

    What I’d like to offer my clients are “microsites” – essentially a single-page site for their property with its own domain name. And I’d like all the data on the page to be pulled from the CPT on my site.

    In a dream world, it would work something like this. Add a new CPT to my site called “Microsites” – You add a microsite as a post and it would have a relational field where I can select the property associated with that microsite, save it and have it post as a subdomain.

    From there, I could use a CNAME to point the subdomain to the actual domain name I wanna use for the property. Hope that makes some sense.

    Is there any way to pull something like this off? Even if it’s a different way than what I described above? Essentially, I just wanna be able to make a standalone property site that pulls data from my Properties CPT so I only have to make updates once.

    Thanks in advance!


  • I’ve solved a similar problem through the use of a Multi site installation and using the switch_to_blog() function to call in what I need.

    In my solution I had a CPT that I wanted to bring into each of my subdirectories and then give the site user the option to select which posts they wanted to see on their site. I think something similar to this would work for you, although as I’m remembering I think I did have to hack about a little to make it work properly.

    Without the hacky-bit in the backend, I would say the easiest method is the following:

    – Setup your site as a subdirectory multisite. You’ll still need to manually create the subdirectory sites, but if you’re going to have to manually setup the CNAMES and stuff anyway, then this doesn’t end up being too much additional work.

    – Clock the ID of the subdirectory.

    – Add a new CPT property post on the core site, with the details of the property. Within this post, add a new field for “multisite” in which you put the SiteID.

    – Make a new page in the multisite, set it as the homepage.

    – Make a child theme for all multisites to use with a front-page.php template with something like the following

    $original_site_id = get_current_blog_id();
    switch_to_blog(1); // 1 is the root blog with all the CPT posts in
    $query_args = array(
    	'post_type'	=>  'properties',
    	'meta_query' => array(
    			'key'     => 'property_site_id',
    			'value'   => $original_site_id,
    $query = new WP_Query($query_args);
    // Continue with standard WP loop and properties output
    restore_current_blog(); // Important to do this for other template requirements in the footer

    That should then give you the option to show a multisite exclusively using ACF fields from your primary website that you can edit everything in one place in one go.

    In practice you can also use this to give each user their own contact forms, newsletter signups etc. which may or may not be useful in the future.

    I would also say that if you decide to give multisite sites ACF fields they need to fill out, it’s much more practical to export those and put them into the child-theme as external files, as they will be auto-created on each site for you.

    Hopefully that helps? 🙂

  • Thank you! I will try this!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘CPT that generates subdomains with fields from other CPT’ is closed to new replies.