Tagged: CPT, metabox, post-to-post relationships
- This topic has 5 replies, 3 voices, and was last updated 7 years, 5 months ago by
Jason.
-
AuthorPosts
-
-
August 12, 2014 at 9:23 am #2209
ianmuscatMemberHi,
I have created a ‘Tests’ CPT using Piklist. I need a way to include the contents of a specific ‘Test’ on a specific page. To do this I have created a metabox that shows up on all pages – the idea is to allow the user to be able to choose from a select box which ‘Test’ they would like to show on that page.
I am assuming that the user would be able to choose the ‘Test’ by name, however, when I then use
get_post_meta()in the template part I shall be including, I would somehow need to pass a post id.Any idea on how this can be accomplished using Piklist? I read a bit about post-to-post relationships, but I’m not sure if it’s what I need.
Additionally, I found an interesting thread by @Jason (https://piklist.com/support/topic/post-relate-select-dropdown/) on what I think is something similar, however, I’m not sure how this would work in my scenario.
Any input/ideas would be most appreciated.
Ian
-
August 13, 2014 at 11:25 am #2226
SteveKeymasterYou can use something similar to this code to display the Post Titles in a dropdown:
,'choices' => piklist( get_posts( array( 'post_type' => 'post' ,'orderby' => 'post_date' ) ,'objects' ) ,array( 'ID' ,'post_title' ) )This will save the Post ID, which you can then use to get the post.
-
August 13, 2014 at 11:53 am #2228
ianmuscatMemberHi Steve,
This works like a charm. I was over complicating my solution. I can’t thank you enough!
You may mark this as resolved.
Ian
-
August 13, 2014 at 12:17 pm #2229
SteveKeymasterAwesome! BTW, This code was pulled from the Piklist Demos > Advanced Tab > Content Section.
The built-in demos has lots of cool example code.
-
August 13, 2014 at 1:15 pm #2231
ianmuscatMemberAwesome. I’ll take a closer look at the demos.
Just out of curiosity, could you provide a scenario for using post-to-post relationships? – I’m not 100% sure I understood their purpose. Would this be similar to having two tables in a DB rated to one another?
I did manage to get most of @jason ‘s code working for my requirements, but I am curious if I could use relate two posts and create select field as opposed to a checkbox section.
Once again, thanks so much for your help!
Regards,
Ian -
August 15, 2014 at 10:20 am #2238
JasonKeymasterHi Ian!
I made a select field a while back for post-to-post relationships: https://gist.github.com/JasonTheAdams/342ad36e9e98269e81c8
The purpose of post-to-post relationships is to create the ability to reference a page/post in either direction. Let’s say I have a product post type and I decide I decide I want an faq post type as well (for an faq archive). I can then add a post-relate field to the faq post type for the products. At that point, when creating an faq post, I can select the corresponding product(s).
From that point on, I can retrieve the corresponding faq post from the product, or I can select all the product(s) from the faq. So if I wanted to show the first 3 questions/answers on the product page, no problem.
Hope this helps! 🙂
-
-
AuthorPosts
- The topic ‘Listing CPT posts in a metabox using Piklist’ is closed to new replies.