I am developing a plugin for question & answer.For that i need to create custom post types question & answer.How to link that custom post types so that if i display a post from Question the related answers should be displayed.How to create two custom posts simultaneously when the plugin is activated?
-
1Please change the title, is not in the context with your question.– bueltgeNov 30, 2014 at 10:32
-
Look in the AgentPress Listings plugin.php file and class-listings.php file.– Brad DaltonNov 30, 2014 at 10:59
-
ok i will check that.– AnoopNov 30, 2014 at 11:10
-
wordpress.stackexchange.com/questions/22749/… This link is good but how to create two post types simultaneously is not mentioned here.You got any idea– AnoopNov 30, 2014 at 11:28
-
function my_create_post_types() { register_post_type( 'my_post_type', $args); register_post_type( 'my_other_post_type', $args); } add_action( 'init', 'my_create_post_types' ); The first link and this function has to be combined in some way.– AnoopNov 30, 2014 at 12:33
1 Answer
WordPress have on default no relationship possibilities for the same objects, like custom post type. But you can create a custom table or use the meta data on each post to create a relationship.
Ready to use
Also it give usable ready solutions:
For a custom solution about meta fields:
You find in this answer helpful hints and the source for a relationshep between the meta data.
-
-
I have enhanced the answer for more understanding. But I haven't add source, was redundant to a usable answer.– bueltgeNov 30, 2014 at 13:36
-
-
The idea is good for adding a field in one post type from other related post type.That is not what iam asking.Suppose we submit an answer for a question,how to relate that question & answer for displaying them correctly.Both questions & answers are seperate cpt.How to display corresponding answers when a question link is clicked.Please check this link shibashake.com/wordpress-theme/add-metabox-custom-post-type– AnoopDec 13, 2014 at 8:45
-
Do you will display the answers to the questions in front end, 2 different CPTs? Or you will display this in a meta box inside the back end on the cpt question? But is not really different. The content inside the meta box or front end have the same loop to get the other CPT with the relationship from CPT "QuestioN" to CPT "Answer".– bueltgeDec 13, 2014 at 19:32