s it possible to create a relation between a custom post type and a regular post?
Let's say that my post is about a movie that I have defined as a custom post type. How do i make such a relation in WP 3.0?
s it possible to create a relation between a custom post type and a regular post?
Let's say that my post is about a movie that I have defined as a custom post type. How do i make such a relation in WP 3.0?
Related it in what sense? In this case would wonder why you even need a custom post type.
I have several authors that write reviews about movies. There can be several reviews (posts) about a movie. I would like to make the movie as a custom post type. Each movie should have a title, description and a EAN-number.
When looking at a movie I would like to link to all the reviews (posts) of that movie.
When looking at a review (post) I would like to link to the movieinformation-page.
Is this possible in WordPress 3.0? And how would I go about it to make it work?
My only problem is how to create a relation between custom posts.
I've actually found two plugins for this:
http://wordpress.org/extend/plugins/custom-post-relationships/
I've tried this plugin, and defined the relation between a movie and a post. But I'm not sure how to edit the template, so that there is links from a movie to the posts and from the posts to the movie.
http://wordpress.org/extend/plugins/custom-post-relationships/
This plugin can only (when writing this) only create relations between posts. It seems as it will be updated in the future to also be able to handle custom posts.
Sorry. The last URL should be
http://wordpress.org/extend/plugins/relation-post-types/
I'm having a problem with this plugin using the widget, it outputs unrelated data.
Is there another way to output related data?
I also have a plugin that supports connections between all post types (including attachments):
scribu, I just installed your plugin-- but i cannot find a meta box in edit-post, or a link in the TOC or anything!
You need to register a connection type. An example is right on the plugin page.
Ah-- via the plugins editor, huh?
Okay-- I have a very limited knowledge of php coding. I can copy and paste your example and I know what to change for my purposes. But in which file do I put it? You don't say, and I've looked though your files and I am not experienced enough to know by their contents.
Ah, sorry about that. Just put in your theme's functions.php file.
You could create a custom write panel with a dropdown box with all movies listed inside it. This way you could create a relation between the two and have them do whatever.
You will need someone with coding knowledge though.
Hey Scribu! Thanks for your amazing plugin!
I got to make the connection, but I have no idea how to query it...
Exemple: I have two related post types called "review" and "movie". I created the relationship between both. ok.
Now I want a query like: On the Movie page, I want to show all reviews related to that movie. What should I do?
Thanks!!!!
Since you're on 04-beta, you can do this:
global $post;
query_posts( array(
'post_type' => 'review',
'connected' => $post->ID,
) );Scribu, would that effectively become a table of contents?
If the post type is arranged hierachally, would the list be in the ordered format?
Scribu, would that effectively become a table of contents?
No, you still have to write the loop to display the found posts.
If the post type is arranged hierachally, would the list be in the ordered format?
Don't know. See the Codex:
http://codex.wordpress.org/Function_Reference/query_posts#Orderby_Parameters
Thanks for your answer Scribu!
I´m sorry, I´m a really begginer on this... so, could you tell me how is the whole query/loop to get the connected posts?
I wrote this, but it doesn´t work:
<?php
global $post;
$the_query = query_posts( array(
'post_type' => 'review',
'connected' => $post->ID,
) );
while ($the_query->have_posts()) : $the_query->the_post();
$do_not_duplicate = $post->ID;
$type = get_post_type();
?>
Thanks for your help!
Ok, sorry... I got it!
Loop inside the main loop:
<?php
global $post;
query_posts( array(
'post_type' => 'review',
'connected' => $post->ID,
) );
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
....
<?php endwhile; endif; ?>
;)
Great!
However, that might cause problems later in the page.
You should use a different loop object, like in your first attempt:
global $post;
$the_query = new WP_Query( array(
'post_type' => 'review',
'connected' => $post->ID,
) );
while ($the_query->have_posts()) : $the_query->the_post();
...
endwhile;
wp_reset_postdata();Ok, so if I already used $the_query in my first loop, now I should use some diferent, like $the_query2 or whatelse, right?
Thanks Scribu!
Yep.
I am trying to show the author(s) for the book on my site's sidebar using this plugin. I have checked the writer's name in the books page (in the admin) but the widget still shows the whole list of the writers instead of showing only the related author. How can I fix that?
This plugin doesn't provide any widgets, so what are you using to display the writers?
I am sorry. I was talking about this plugin:
http://wordpress.org/extend/plugins/relation-post-types/
Is there a way to define meta for the relationship between two post types?
Like the product-store example:
product - 20eur - store1
product - 22eur - store2
With Posts 2 Posts there is. See:
http://wordpress.org/support/topic/plugin-posts-2-posts-how-to-add-info-to-connection
scribu, why don't you add widgets and admin setting options to this plugin. Apparently yours is the most advanced plugin for this purpose but needs a lot of PHP knowledge to use it.
Because widgets would either be very limited or be very heavy, option wise.
This topic has been closed to new replies.