WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Unable to connect to existing post (12 posts)

  1. alafrizr
    Member
    Posted 5 months ago #

    I'm attempting to use Posts to Posts to connect research projects to publications on a research lab's website, but I'm running into trouble when I try to actually create the connection.

    According to the tutorials I've found, I should be able to search through the pool of appropriate post types using a search field and "View all" button. However, when I try to build the connection, the search box is unresponsive, and the "View all" button is missing.

    I can create a connection to a new post using the "New" tab, but that post still won't appear using the search tab, so I'm unable to create the many-to-one cardinality I need here.

    Am I overlooking something obvious? Can anybody help me out?

    https://wordpress.org/plugins/posts-to-posts/

  2. tedinoz
    Member
    Posted 5 months ago #

    Please show the code you are using to register the connections.

  3. alafrizr
    Member
    Posted 5 months ago #

    As per this tutorial, I've used the following code to try and set up connections between projects and publications, and students and directors.

    <!-- Posts 2 Posts -->
    
    <?php
    function pw_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' => 'projects_to_publications',
            'from' => 'project',
            'to' => 'publication'
        ) );
    
            p2p_register_connection_type( array(
            'name' => 'student_has_supervisor',
            'from' => 'student',
            'to' => 'director'
        ) );
    }
    add_action( 'wp_loaded', 'pw_connection_types' );
    ?>
  4. tedinoz
    Member
    Posted 4 months ago #

    Hi
    Sorry for not getting back sooner; I forget to request a reminder email. Anyway...

    When you click in the Search Box, does FireBug or Chrome Developer tools, report a console message along the lines of a "Malformed Response"? In my case, this error meant that there was a problem with the encoding of my plugin file (or functions.php, in my case).

    I suggest you double-check your plugin file and make sure that it is properly encoded. That is, make sure that is NOT encoded for BOM. Even if the file encoding 'seems' right, I usually convert to another format, save, then convert again to the right encoding.

    Ted

  5. alafrizr
    Member
    Posted 4 months ago #

    That is exactly what the console says. Could you please explain how to check the encoding of the plugin? I'm new to WordPress, so I've just been learning as I go for this project.

    I don't know if this is relevant, but since installing the plugin, I've also had issues loading both the front-end and the admin interfaces (just displays a blank page). I've been getting around it by temporarily renaming the theme folder and refreshing the page before changing it back. It just occurred to me that it might be related.

    Thanks for the response. I've been stumped for weeks.

  6. tedinoz
    Member
    Posted 4 months ago #

    alafrizr, I wouldn't be surprised if all the issues are related.

    Look in your text editor for encoding options. Open the plugin file, select the option to encode in "UTF-8 without BOM", and save the file. Refresh your browser tab and click the Search Box - everything should work.

    You might need to read the fine print in the editor's help. For example Notepad++ (which I use): when you encode as "UTF-8 without BOM", the file format then appears as "ANSI as UTF-8". In TextWrangler the release notes says that "Unicode (UTF-8, no BOM)" has been renamed to "Unicode (UTF-8)", and Unicode (UTF-8)" has been renamed to "Unicode (UTF-8, with BOM)"."

    Ted

  7. alafrizr
    Member
    Posted 4 months ago #

    I've now tried saving it with a different encoding, then back to UTF-8 (using TextWrangler), but I'm not seeing any change. I'm still getting the malformed response error too:

    Malformed response
    <!-- Posts 2 Posts -->
    
    {"rows":[{"columns":[{"column":"create","content":"<div data-item-id=\"108\" title=\"http:\/\/localhost:8888\/director\/kim-j-vicente\/\">\n\t<span class=\"p2p-icon\"><\/span>\n\tKim J. Vicente<\/div>\n"}]},{"columns":[{"column":"create","content":"<div data-item-id=\"81\" title=\"http:\/\/localhost:8888\/director\/justin-hollands\/\">\n\t<span class=\"p2p-icon\"><\/span>\n\tJustin Hollands<\/div>\n"}]},{"columns":[{"column":"create","content":"<div data-item-id=\"79\" title=\"http:\/\/localhost:8888\/director\/greg-jamieson\/\">\n\t<span class=\"p2p-icon\"><\/span>\n\tGreg Jamieson<\/div>\n"}]}]}

    When you refer the "plugin file" do you specifically mean "/plugins/posts-to-posts/posts-to-posts.php"? Because I've been attempting this fix on that file and functions.php. No dice so far though.

  8. tedinoz
    Member
    Posted 4 months ago #

    OK. My bad.

    First up, you don't need to touch "/plugins/posts-to-posts/posts-to-posts.php" (or any of the other files in the P2P plugin). I only mentioned a plugin file because some users create a separate plugin for their connection registrations rather than using "functions.php".

    Your code to register connections is shown above - did you put this in "functions.php"? And you've re-edited this and confirmed that this is encoded properly.

    OK, did you create or change any other files - maybe a theme template file to display the linkages between posts? Check those also.

    Are you running this on-line or in development? Because the other thing I did was to switch themes (to twentyten or similar), copy-paste the registration codes into the twentyten "functions.php", and see if it works.

    I'm also trying to think of a way to give you hands-on help rather than batting this back and forth.

    Ted

  9. alafrizr
    Member
    Posted 4 months ago #

    Hi, thanks again for all this help. I'd be completely lost otherwise.

    Yes the connection registrations are in the functions.php file of a child theme. I've made a custom theme for this project, so all my pages are custom pages running on top of the parent theme.

    I'm running all this locally for now. I've tried pasting the registration code into the functions.php for a number of standard themes, but they all result in the White Screen of Death until I remove the code.

    I've also tried stripping the site down to the bare minimum by doing the following:
    - reinstalling the parent theme
    - removing everything in the child theme folder
    - creating a new stylesheet that only imports the parent stylesheet
    - creating a new functions.php file containing only the registration code for a basic post-to-post connection:

    <!-- Posts 2 Posts -->
    
    <?php
    function pw_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' => 'posts_to_posts',
            'from' => 'post',
            'to' => 'post'
        ) );
    }
    add_action( 'wp_loaded', 'pw_connection_types' );
    ?>

    Still getting the malformed response error.

  10. alafrizr
    Member
    Posted 4 months ago #

    Update: I decided to try reinstalling the entirety of WordPress, Posts to Posts, and using the bare-bones child theme mentioned in my last post. The error persists.

  11. tedinoz
    Member
    Posted 4 months ago #

    Yep. Reinstall WP, disabled all plugins, reinstalled plugins one-by-one, etc, etc - sounds familiar. It was only when I started playing around with a different theme that I started to make progress. Haven't had much/any experience of child themes but I don't think that would be the heart of the problem.

    BTW, what version of WordPress are you running?

    If you wish, upload your functions.php here; I'll look at it and try it on my system.

    Ted

  12. alafrizr
    Member
    Posted 4 months ago #

    No need! It's finally working.

    It looks like it ended up being something stupidly minor: the HTML comment declaring the Posts to Posts section was somehow breaking the interface. After removing it, I can now see the list of posts to connect to.

    Thank you so much for the ongoing help this past week. Hopefully I'll be okay from here on out.

Reply

You must log in to post.

About this Plugin

About this Topic