Title: [Plugin: Posts 2 Posts] shortcode, template, the_content()
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] shortcode, template, the_content()

 *  [Francois Lamotte](https://wordpress.org/support/users/francoislamotte/)
 * (@francoislamotte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/)
 * Hello Scribu,
 * I’m working with the shortcode templates. (latest version of your plugin)
 * With the templates, I could reach every fields of a connected post/page except
   the_content();
 * Everything else is displayed like :
 *     ```
       the_title();
       the_permalink();
       the_meta();
       ```
   
 * But the_content(); creates a loop.
 * I’ve tried some turnaround but as I not a dev, I’m not working in a proper way.
 * Do you have any suggestion for me?
 * Thank you,
 * François
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 9 replies - 1 through 9 (of 9 total)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780514)
 * Please post the relevant code (P2P filter + template file) in a [http://pastebin.com](http://pastebin.com)
 *  Thread Starter [Francois Lamotte](https://wordpress.org/support/users/francoislamotte/)
 * (@francoislamotte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780606)
 * Hi Scribu,
 * Thank you for your answer.
    - [The static page (output for the final design)](http://dev3.pointben.net/iphoto-comment-enlever-les-yeux-rouges/)
    - [The current dynamic version (simple listing of p2p shortcodes)](http://dev3.pointben.net/lecon/comment-enlever-les-yeux-rouges?view-template=Lecon)
    - Currently I’ve made a list of p2p-….php templates linked to the shortcodes.
    - The code in that pages are simple[ like this example on pastbin.com](http://pastebin.com/wiELp3Tf)
    - **My first question** : when I add the_content(); in that kind of template,
      I got kind of loop that produce an output (after 1′ ) with a very long repetition
      of the same content.
    - **FYI **: here the p2p shortcodes are handled through the WP-VIEWS plugin (
      using their shortcode template mechanism).
    - Thank you for your time and support.
    - Regards
    - F
    - If you want more details
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780607)
 * You didn’t post the relevant code, i.e. the code that takes a list of connected
   posts and loops through them.
 * Also, I don’t understand how P2P shortcodes are routed to templates. I assume
   the WP-Views plugin can only generate standard shortcodes, which implies that
   the code from P2P isn’t used at all.
 * Edit: what I’m asking for is your version of the code shown here:
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Actions-and-filters](https://github.com/scribu/wp-posts-to-posts/wiki/Actions-and-filters)
 *  Thread Starter [Francois Lamotte](https://wordpress.org/support/users/francoislamotte/)
 * (@francoislamotte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780608)
 * In my functions.php, I’ve copied [the shortcode handler from your wiki](http://pastebin.com/eDSUpUks)
 * And in WP-VIEWS, [my template is that one](http://pastebin.com/5mgrSkL6).
 * From there, p2p shortcodes are calling the bunch of p2p-list-… .php templates
   [that are rendered on that page](http://dev3.pointben.net/lecon/comment-enlever-les-yeux-rouges?view-template=Lecon).
 * I don’t know if this method is appropriate.
 * Another question related to this logic, is that I’m interested to retrieve an
   URL value in a connected custom field, and to inject it into an other shortcode(
   for a video player). I retrieve the value but I don’t understand yet how I will
   use it … (the value is just under the picture (below VIDEO title).
 * I’m sorry if i’m doing dumb stuff … 😛
 * F
 *  Thread Starter [Francois Lamotte](https://wordpress.org/support/users/francoislamotte/)
 * (@francoislamotte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780610)
 * I’ve seen different kind of connexion like
 *     ```
       $connected = get_posts( array(
         'connected_items' => $zone_posts,
         'connected_type' => array( 'CONNECTION_TYPE1', 'CONNECTION_TYPE2', ... ),
         'connected_direction' => 'any',
         'post_type' => 'any',
         'suppress_filters' => false
       ) );
       ```
   
 * But i don’t know how to handle that with the shortcode logic. I’m sure that could
   help to reduce the number of queries.
 * And after that as for each connexion I need to extract different fields, … I 
   am a little bit lost 🙂
 * F
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780621)
 * Don’t query multiple connection types unless you plan to show them together. 
   The lower query count isn’t worth the extra complexity.
 * Back on topic: using the_content() works fine for me, since the `$post` global
   is changed before each template load.
 * The only situation that I could imagine where this wouldn’t work would be if 
   you have a post connected to itself.
 *  Thread Starter [Francois Lamotte](https://wordpress.org/support/users/francoislamotte/)
 * (@francoislamotte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780627)
 * For the topic the_content(), I understand that it works for you but I don’t know
   how to handle it in my case.
 * In the “master template”, I need to place different shortcodes on multiple places.
   And each places has different elements to render.
 *     ```
       | p2p_cp_video_url | current_post_title + current_post_excerpt |
       | p2p_cp_sales_arg_content | p2p_cp_free_training_content |
       | p2p_cp_testimonial_title + excerpt | xxxx |
       ```
   
 * So maybe I don’t get the concept of templates for shortcodes, but I can’t figure
   how to handle different pieces through one connexion and where to place that 
   piece of code.
 *  Thread Starter [Francois Lamotte](https://wordpress.org/support/users/francoislamotte/)
 * (@francoislamotte)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780628)
 * or maybe the idea to use shortcodes for that kind of template is not a good one?
 * going straight to standard templates will simplify the process?
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780629)
 * > going straight to standard templates will simplify the process?
 * It might. Just don’t start using p2p_list_posts(). 🙂

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘[Plugin: Posts 2 Posts] shortcode, template, the_content()’ is closed
to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

 * 9 replies
 * 2 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-shortcode-template-the_content/#post-2780629)
 * Status: not resolved