Title: [Plugin: Posts 2 Posts] String replacements
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] String replacements

 *  Resolved [Troy Chaplin](https://wordpress.org/support/users/areziaal/)
 * (@areziaal)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/)
 * I’m wondering if it’s possible to do a string replacement on the_title when it
   is being outputted from a reciprocal connection? Did not see any specific information
   about this in the github doc area, unless I somehow overlooked it?
 * Any help would be greatly appreciated.
    Thanks
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/#post-2778698)
 * Do you mean in the metabox or in The Loop or where? More context please. kthnxbye.
 *  Thread Starter [Troy Chaplin](https://wordpress.org/support/users/areziaal/)
 * (@areziaal)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/#post-2778729)
 * It’s within the loop on a custom post type archive page. Using your docs I’ve
   set the reciprocal connection like:
 *     ```
       <?php $connected = p2p_type( 'progs_to_progs' )->get_connected( $post->ID );
       	p2p_list_posts( $connected, array(
       	'before_list' => '',
       	'after_list'  => '',
       	'separator'   => ', Master of ',
       ) ); ?>
       ```
   
 * We’ve tried a couple ways to do a string replacement on the title that gets output,
   but had no luck.
 * In the query I’m setting a variable:
 * `$datitle = get_the_title();`
 * Then directly before the connection I have:
 * `<?php echo str_replace(' (Master’s)', '',$datitle) ?>`
 * I’m looking to do the same replacement on the_title output from the connected
   posts so the output will read as:
 * Aerospace Engineering, Master of Engineering, Master of Applied Science
 * Currently, it reads as:
 * Aerospace Engineering, Master of Engineering (Master’s), Master of Applied Science(
   Master’s)
 * *with Master of Engineering (Master’s) and Master of Applied Science (Master’s)
   being the items connected to Aerospace Engineering in the output
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/#post-2778735)
 * If you check the docs again, you will see that p2p_list_posts() is no longer 
   used, precisely because it’s hard to customize:
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage](https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage)
 *  Thread Starter [Troy Chaplin](https://wordpress.org/support/users/areziaal/)
 * (@areziaal)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/#post-2778747)
 * Ok thanks, I’ll go back and read things more thoroughly. I was going by this 
   [page here](https://github.com/scribu/wp-posts-to-posts/wiki/Using-p2p_list_posts%28%29),
   and everything worked fine, until I started looking at the need for the string
   replacement.
 * I’m guessing some of the info in [Looping the Loop](https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop)
   is where I should be focusing my efforts?
 *  Thread Starter [Troy Chaplin](https://wordpress.org/support/users/areziaal/)
 * (@areziaal)
 * [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/#post-2778776)
 * Just came back to follow up, and close this ticket. Thanks for doing that already.
 * So, minus some smaller stuff like a separator, the Looping the Loop section worked
   perfectly! So now, within the loop I have:
 *     ```
       <?php
       	$connected = p2p_type( 'progs_to_progs' )->get_connected( $post );
   
       	while ( $connected->have_posts() ) : $connected->the_post();
       	$connectedtitle = get_the_title();
   
       	echo str_replace(' (Master’s)', '',$connectedtitle);
   
       	endwhile;
   
       	wp_reset_postdata();
       ?>
       ```
   
 * Thanks scibu! Appreciate the help, as well as this awesome plugin!

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

The topic ‘[Plugin: Posts 2 Posts] String replacements’ 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/)

 * 5 replies
 * 2 participants
 * Last reply from: [Troy Chaplin](https://wordpress.org/support/users/areziaal/)
 * Last activity: [13 years, 12 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-string-replacements/#post-2778776)
 * Status: resolved