WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] 1.2 changes behavior of p2p_list_posts (with custom template) (6 posts)

  1. Manuel Schmalstieg
    Member
    Posted 2 years ago #

    I believe that the 1.2 update of the plugin has introduced a difference in the output generated by the p2p_list_posts utility function that is described here:

    https://github.com/scribu/wp-posts-to-posts/wiki/Using-p2p_list_posts%28%29

    The default usage of the p2p_list_posts function is not affected, it still outputs this:

    <ul>
      <li>
        <a href="HYPERLINK">TITLE</a>
      </li>
    </ul>

    The issue appears when I use a custom template with this syntax:

    p2p_list_posts( $post->connected, array(
      'template' => 'my-custom-template.php'
    ) );

    Instead of replacing the default output with 'my-custom-template.php', it appends the default ouput after the custom part.

    So if 'my-custom-template.php' would contain only the word 'TEST', we would see this output:

    <ul>
      <li>
        TEST
        <a href="LINK">TITLE</a>
      </li>
    </ul>

    It looks like there is no way to get rid of that unwanted default part. Did the "template" feature become unsupported? Should I avoid using p2p_list_posts, and rather create a loop instead?

    Related post:
    http://wordpress.org/support/topic/plugin-posts-2-posts-templates-for-p2p_list_posts

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

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    That's a bug that was introduced along with the 'separator' parameter.

    Fixed in the development version (1.3-alpha).

    Thanks for reporting.

  3. Manuel Schmalstieg
    Member
    Posted 2 years ago #

    Good to know! In the meantime I have resolved my problem by using a normal loop, as I needed to do some more complicated things with the output.

    Side question: using p2p_list_posts and a custom template, I wonder if it is possible inside the custom template to define variables, such as:

    $custom_title_var = get_the_title();
    $custom_url = get_permalink();

    and use them later in the loop for some conditional processing?

    When I try to do that, it doesn't ouput anything, whereas using the_title() or the_permalink(); I obtain the expected values.

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    Those variables are reset on each iteration. You could make it work if you defined them as globals first, but I suggest you go with a plain loop instead of p2p_list_posts() in that case.

  5. Manuel Schmalstieg
    Member
    Posted 2 years ago #

    Fine. Thanks for clarifying this!

  6. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    I went ahead and removed the 'template' parameter since it required messing with the $post global, which was causing problems:

    http://wordpress.org/support/topic/plugin-posts-2-posts-custom-admin-boxes-example-mess-up-wp_query

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic