• I am trying to create a coupon website for which I have created 2 custom post types “Vendor” and “Coupons”.

    Basically, I first want the user to add a vendor and then upload coupons through the front-end form.

    The URL structure I am expecting is https://www.domain.com/vendor/coupons/

    Here /coupons/ page will be the archive page for coupons for the selected vendor.

    For this, I have created vendor CPT with the hierarchical feature as “true”.

    I have read various posts on StackOverflow that say rewriting URLs is an answer to this. But the problem with that was It was showing coupon individual post page and not archive page. Also, I am using wp user frontend pro for collecting frontend submissions which don’t allow selecting parent while creating a new post.

    For the coupon feature, I am using 4 custom fields using ACF: “Vendor”, “Coupon title”, “Coupon Description” & “Coupon code”.

    Here the vendor field can be used for filtering out the results of the coupons archive.

    Please guide me on the correct way of implementing this kind of feature.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anonymous User 14808221

    (@anonymized-14808221)

    Typically “Hierarchical” posts are only possible within native WordPress Pages by default and even if you enable “hierarchal” on other post types (which is possible) you couldn’t connect 2 completely different post types in this type of hierarchy.

    What you are looking for here, would rather be a “Post Relationship”. And, additionally, a relatively complex rewrite mechanism to generate the URL you are looking for.

    I know of a number of plugins that can help you with the First ask (relationships), amongst which go Toolset Types, PODS and MetaBox. Only PODS is amongst the free plugins doing this task.

    For the rewrite Rules, I am not feeling comfortable to answer here as it would need a respectable amount of custom code, which I could well craft but is above the scope of this forum.

    It might be that someone else in this forum has a genial idea as of how to rewrite Urls using a Post Relationship, so I do hope that someone can chime in and share their ideas as of how this could be achieved without a considerable amount of code.

    Moderator bcworkz

    (@bcworkz)

    Because you can rewrite URLs, your choice of data schema is not rigidly tied to URL structure. But if you can avoid rewrites and utilize the default URL structure, all the better. It’s not unheard of for one post type to be a child of another. We see this with posts and their media attachments. Implementing such a scheme involves manipulating the posts query’s “post_type” query var. It’s better if the parent post type were non-hierarchical so there is no ambiguity between children of the same type and posts of the other type. I’m unsure how WP resolves this regarding child pages and attachments. And you do need an added rewrite rule to accommodate the unexpected extra element in the URL structure.

    The simplest solution is to make all top level coupon posts actually be a vendor. The child posts would be the actual coupons. Then the domain.com/coupons/vendor_name/coupon_name/ URL structure would be used by default. Not the most intuitive schema for us humans, but WP doesn’t care that top level coupons are not really coupons.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom Post Type as a Parent of another Custom Post Type’ is closed to new replies.