Tag Info

Hot answers tagged

6

Just call p2p_connect( $id_of_post_type_a, $id_of_post_type_b ); in the form handling code.


4

Why not do... $my_post_types = array( 'post', 'page', 'topic', 'case', 'note', 'question', 'therapy_guideline' ); p2p_register_connection_type( array( 'name' => 'my_post_relationships', 'from' => $my_post_types, 'to' => $my_post_types, 'sortable' => 'any', 'reciprocal' => false, ...


4

Ok, so the idea is that you have an outer loop, that displays the tours. And then you have an inner loop, that displays each artist. The way The Loop works is that it populates a lot of global variables, such as $post, so it looks like magic. Let's look at a more uniform approach: $tours = get_posts( array( 'post_type' => 'tours', 'nopaging' ...


4

Yes it is. First you have to combine the results in one array: $all_posts = array_merge( $related->posts, $features->posts ); Now, let's sort the array items by date: usort( $all_posts, function( $a, $b ) { return strcmp( $b->post_date, $a->post_date ); } ); Finally, do the loop: global $post; foreach ( $all_posts as $post ) { ...


3

GhostToast seems to have answered your issue with repetition. Implementing this for your specific situation should show related content: https://github.com/scribu/wp-posts-to-posts/wiki/Related-posts: $related = p2p_type( 'posts_to_pages' )->get_related( get_queried_object() ); The only difference is that we replaced get_connected() with ...


3

Yes, it was actually 'connected_orderby' instead of 'p2p_orderby'. Also, this can be done via drag-and-drop since version 0.9: https://github.com/scribu/wp-posts-to-posts/wiki/Connection-ordering


2

This is not really a WP_Rewrite question, unless you want to include the post ID in the URL. I think the best way to solve this is, as you suggest, do a get_posts() query with your slug, and change the variables from there. Of course you don't have to do this on every init, only do it when you are at a clubs/[club_slug]/news/ page. So first create a rewrite ...


2

try 'connected' => get_queried_object_id() instead of 'connected_from' => get_queried_object_id()


2

With the development version of the plugin (0.8-alpha), you have a 'p2p_orderby' query var, which you can use with WP_Query, like so: $my_query = new WP_Query( array( 'connected_to' => get_queried_object_id(), 'p2p_orderby' => 'my_connection_field' ) ); More info on connection fields: ...


2

Yes, there is a way to do this, since version 0.8: https://github.com/scribu/wp-posts-to-posts/wiki/Connection-ordering


2

No, it isn't possible without modifications to the p2p plugin, as indicated here: https://github.com/scribu/wp-posts-to-posts/issues/374 Relevant code is here: https://github.com/scribu/wp-posts-to-posts/blob/master/core/connection-type.php#L374


1

I finally found the answer. Turns out I just needed a better understanding of WPQuery. It ended up being as simple as: function order_pages_by_ID( $args, $ctype, $post_id ) { if ( 'posts_to_pages' == $ctype->name ) { $args['meta_key'] = '_event_start_date'; $args['orderby'] = 'meta_value'; $args['order'] = 'asc'; } } ...


1

You will just have to call get_children() for each gallery: $images = array(); foreach ( $gallery_posts as $gallery ) { $images = array_merge( $images, get_children( 'post_parent' => $gallery->ID, ... ) ); }


1

So, in my case this way hepled: 1) I've replaced 'composer' with 'author' in functions.php (in that part where connections are being registered) and 2) "edited" data in ${wpdb}_p2pmeta using phpmyadmin (UPDATE <yourprefix>_p2pmeta SET meta_value = "author" WHERE meta_value = "composer" or manually or like that). Please, backup your data, please test ...


1

You can fix it by adding a 'name' parameter to your p2p_register_connection_type() call, as shown in the wiki: https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage


1

Not sure if you really need to use the custom admin boxes, unless you need to customize labels, etc... <?php function my_connection_types() { // Make sure the Posts 2 Posts plugin is active. if ( !function_exists( 'p2p_register_connection_type' ) ) return; p2p_register_connection_type( array( 'name' => 'cpt1_to_cpt2', ...


1

I've dealt a similar requirement and so far the best way to do that is by using a custom field to save the related term id. That means for each 'practice-area' post type, there will be a 'specialty-term-id' custom field with the 'specialty' term id as value. Here the action hook to create the term for each post add_action( 'save_post', ...


1

I know this question is old, but I just spent an hour researching this problem as well. Within the main post that has multiple things related to it, in the sidebar (where connections are created), you can drag and drop to reorder the connected posts! That is how they will appear when called. Very intuitive once you realize it's there, but not immediately ...


1

The actual question for me is: For what and how do you use the relationship information? Where is it displayed or do you need it for any further business logic? As far as I know, there is no way with core functions for this. If I wanted to achieve something like this without a plugin in the past, I wrote some custom PHP that automatically adds a taxonomy ...


1

The best way to do that would be to register a non-hierarchical taxonomy, shared between the different post types you want to associate. You can then use WP's built-in taxonomy querying to pull all associated content for any term. As a general rule of thumb, anything you're going to query by should be a taxonomy rather than a field, because querying by ...



Only top voted, non community-wiki answers of a minimum length are eligible