WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
Problem upgrading from 1.1.5 to 1.1.6 (19 posts)

  1. jtwg
    Member
    Posted 2 years ago #

    None of the custom connected items show up where they used to.

    This happens a lot with this plugin. Really makes upgrading a huge roll of the dice. The author should probably include some documentation about any settings that might need to be changed in the future.

    http://wordpress.org/extend/plugins/posts-to-posts/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    None of the custom connected items show up where they used to.

    Please be more descriptive. What connection type do you have? Where were they supposed to show up? etc. etc.

  3. Dave James Miller
    Member
    Posted 2 years ago #

    I have the same issue, but first I'm afraid I have to agree with "Really makes upgrading a huge roll of the dice" - minor version upgrades in P2P regularly break backwards compatibility. I don't want to complain too much because it's free and it's a very useful plugin, but semantic version numbers and more information in the change log would be greatly appreciated!

    The first error I got after upgrading was this:

    Warning: Invalid argument supplied for foreach() in /.../posts-to-posts/core/query.php on line 95

    (Note: I get this error even when I'm not using P2P in the query at all, so I think that's a separate bug.)

    Then I added this to the query:

    'connected_type' => 'case_studies_to_staff'

    That removed the error message, but now I get no results at all, the same as jtwg.

    I also changed 'connected_from' => get_queried_object_id(); to 'connected_items' => get_queried_object_id() as shown on the wiki, but it didn't make a difference.

    My functions.php contains this:

    add_action('init', 'init_p2p', 100);
    function init_p2p() {
        p2p_register_connection_type(array(
            'name'  => 'case_studies_to_staff',
            'from'  => 'case-studies',
            'to'    => 'staff',
            'title' => 'Staff',
        ));
    }

    The widget looks like this (I have removed all irrelevant options):

    $query = new WP_Query(array(
        'post_type' => 'staff',
        'connected_type' = 'case_studies_to_staff',
        'connected_items' = get_queried_object_id(),
    ));

    This is what worked correctly in the previous version:

    $query = new WP_Query(array(
        'post_type' => 'staff',
        'connected_from' = get_queried_object_id(),
    ));

    If there's anything else that would help debug it just let me know. For now I'm going to downgrade back to 1.1.5.

    Thanks
    Dave

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Yeah, adding multiple connection type queries in a minor release was a mistake.

    $query = new WP_Query(array(
        'post_type' => 'staff',
        'connected_from' => get_queried_object_id(),
    ));

    Granted, this used to work, but it was intended only for the migration script, which sometimes fails, precisely because queries without a connection type are inexact.

    Let it be known: Queries without a 'connected_type' parameter are no longer supported.

    This should work:

    $query = new WP_Query(array(
        'connected_type' => 'case_studies_to_staff',
        'connected_items' => get_queried_object_id(),
    ));

    provided that get_queried_object_id() returns either a case study ID or a staff ID.

  5. jtwg
    Member
    Posted 2 years ago #

    Thanks for the reply, scribu.

    Question for you: I have a table full of already established connections - will your plugin update those rows to add the connected_type if I provide it in my connection registrations? Or will the connections need to be re-created?

    This is a problem I've run into a lot, needing to re-establish already present connections to provide missing values in the new fields.

    Please advise, thanks.

    P.S. agree with Dave about that I also don't want to complain too much, for the same reasons he cites. I love this plugin, and use it on a great many sites. It's incredibly useful. Semantic versioning and more explicit changelogs would definitely make it even more useful because the broken backwards compatibility really causes a lot of problems on production sites.

  6. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    You said you were upgrading from 1.1.5 to 1.1.6, so all connections should already have the p2p_type column populated.

    If the connection type has no 'name' parameter when it's defined, the p2p_type column will be filled with a generated hash.

    Here's more info:

    http://wordpress.org/support/topic/plugin-posts-2-posts-all-existing-connection-gone?replies=15#post-2517920

  7. psnepsts
    Member
    Posted 2 years ago #

    I have similar woes with the 1.1.6 upgrade. In my case, I have nested loops that draw connected information from the $post->ID (as opposed to get_queried_object_id()). I have 3 Custom Post Types to to run an event system for a comedy festival: tscf-troupes, tscf-shows, and venues. Each show can have multiple troupes attached to it, but only one venue. Each troupe can be attached to multiple shows.

    Here's what my template's 'single' looks like for a particular "Troupe:"

    http://pastebin.com/vVWwYcR4

    The first query seeks to get all 'tscf-shows' that the current 'tscf-troupe' is attached to and display each.

    The second query is a sub-query that seeks to get the 'venues' that is attached to each show that is returned in the first query, and output its address.

    The third query, also a sub-query, seeks to find the name of each 'tscf-troupe' that is featured on each show from the first query, and output a link to that troupe's page. (The current troupe would also output in this list with a link to the current page).

    Now - prior to the 1.1.6 upgrade, these all worked smoothly. Should I downgrade to 1.1.5? If so, I'm committing myself to sticking with that version and I'm not sure that's the best idea.

    Any ideas here would be very much appreciated.

  8. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    That looks like correct usage. Will investigate soon.

    For the nested loops, you should try using each_connected():

    https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop

    (added an example for using it multiple times on the same outer query)

  9. psnepsts
    Member
    Posted 2 years ago #

    In this case, is 'actors' the name of the post_type?

    p2p_type( 'movies_to_actors' )->each_connected( $my_query, array(), 'actors' );

  10. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    No, it's the key used to store the list of actors on the $post object: $post->actors.

  11. psnepsts
    Member
    Posted 2 years ago #

    Also, I presume that:
    p2p_list_posts( $post->actors );

    simply outputs a list of links to associated posts.

    In the example I am using above, I used to be able to loop over the results and access the post_meta for each to output, for example, a link to a map that is generated using a custom field for the venue's address.

  12. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    foreach ( $post->actors as $post ) {
      setup_postdata( $post );
    
      print_r( get_post_meta( $post->ID ) );
      ...
    }
    
    wp_reset_postdata();

    Would you like some fries with that?

  13. psnepsts
    Member
    Posted 2 years ago #

    Well... no wonder I wasn't getting my pages as I had thought they should be. All of my existing connections have been blown out.

  14. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Define "blown out".

  15. psnepsts
    Member
    Posted 2 years ago #

    All connected posts previously entered have been disassociated from one another. In my example, an entry for a post_type of 'tscf-show' would be connected to a number of 'tscf-troupes' entries, and one 'venues' entry. This update has resulted in the connections I'd made in the past no longer being present.

  16. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    I don't think that's accurate. They should still be in the wp_p2p table.

  17. psnepsts
    Member
    Posted 2 years ago #

    There are no Venues or Troupes in the meta boxes of the add/edit pages. It's as if I did not associate them at all.

  18. psnepsts
    Member
    Posted 2 years ago #

    I should add, that when I re-added a few, some of my template pages started displaying as expected.

  19. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    There are no Venues or Troupes in the meta boxes of the add/edit pages.

    That's why I suggested you look directly at the wp_p2p table in your database, using something like phpMyAdmin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic