• Resolved Steve

    (@steveconley)


    Hi. I’ve tried to find the solution for this with no luck. I apologize if I missed the documentation or another thread for it.

    I have two custom post types: Webcomics and Creators and they have bi-directional fields called Webcomic creator (webcomic_creator in the Project pod) and Webcomic projects (webcomic_projects in the creator pod).

    On a Webcomic post, I’m showing the associated Creator(s) and want to create a list of “Other webcomics by this creator) and have the following template…

    (The Pod Reference is set to “Webcomics”)

    [each webcomic_creator]
    Projects by {@post_title}<br>
    [each webcomic_creator.webcomic_projects]
    <a href="{@permalink,esc_url}">{@post_title}</a><br>
    [/each]
    [/each]

    This works great. It produces – on a Webcomic post – a list of the all the webcomics by each associated creator – including the post we’re currently on. Is there a way, within pods (or the shortcode which calls this template), to present this list but exclude the current post?

    Basically, I want to have a section called “Other webcomics by this creator” and not include the page the user is already staring at. ??

    Thanks for your help and for an amazing plugin!

    — Steve

    • This topic was modified 3 years, 8 months ago by Steve.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Paul Clark

    (@pdclark)

    Hi Steve,

    The [if] shortcode can’t be used for logical comparisons, so it has to be done in PHP. Here’s code that can be used in your template for the desired effect:

    <?php
    $webcomic = pods( 'webcomic', get_the_ID() );
    
    foreach( $webcomic->field( 'webcomic_creator' ) as $webcomic_creator ) {
    	?>
    	Projects by <?php echo get_the_title( $webcomic_creator['ID'] ); ?><br/>
    	<?php
    	$creator = pods( 'creator', $webcomic_creator['ID'] );
    	foreach ( $creator->field( 'webcomic_projects' ) as $project ) {
    		if ( (int) $project['ID'] === (int) get_the_ID() ) {
    			continue;
    		}
    		?>
    		<a href="<?php echo esc_url( get_the_permalink( $project['ID'] ) ); ?>">
    			<?php echo get_the_title( $project['ID'] ); ?><br/>
    		</a>
    		<?php
    	}
    }
    Thread Starter Steve

    (@steveconley)

    Paul, that’s brilliant! Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘List of other posts – excluding the current post’ is closed to new replies.