WordPress.org

Support

Support » Plugins and Hacks » Posts 2 Posts » [Resolved] [Plugin: Posts 2 Posts] String replacements

[Resolved] [Plugin: Posts 2 Posts] String replacements

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author scribu

    @scribu

    Do you mean in the metabox or in The Loop or where? More context please. kthnxbye.

    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

    @scribu

    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

    Ok thanks, I’ll go back and read things more thoroughly. I was going by this page here, 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 is where I should be focusing my efforts?

    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 ‘[Resolved] [Plugin: Posts 2 Posts] String replacements’ is closed to new replies.
Skip to toolbar