• Resolved SidianMSJones

    (@sidianmsjones)


    So I have a template made to show related post types called Meanings which are related to one another (a blue bird is related to blue is related to color, etc). It worked perfectly and one day just stopped! Can you see anything wrong with my setup?

    The shortcode
    [pods name="meaning" template="Related To Template" limit="5"]

    The template

    [each related_to]
    <div class="related-to-list">
    	<a href="{@permalink,esc_url}">
    		<div class="related-to-image">
    		<img src="{@esc_url}" class="related-to-image">{@post_thumbnail.50x50}
    		</div>
    		<div class="related-to-title">{@post_title}
    		</div>
    	</a>
    </div>
    [/each]

    The page I need help with: [log in to see the link]

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Support Paul Clark

    (@pdclark)

    While testing this, some things I had to make sure of going along the way:

    • Are the template title “Related To Template” as written in the shortcode and as written in the Template title exactly the same? For example, a lowercase “t” in “To” might throw it off.
    • The field > Advanced Field Options reads “Multi-select”
    • It doesn’t have a bi-directional relationship with itself.

    After all that, putting your template code in worked for me, as long as a relationship field was selected.

    The below shortcode should do the same thing with [meaning_related_to]:

    <?php
    
    add_shortcode(
    	'meaning_related_to',
    	function(){
    		ob_start();
    		// Get this meaning
    		$meaning = pods( 'meaning', get_the_ID() );
    
    		echo '<div class="related-to-list">';
    
    		// Loop through related Meanings.
    		$related_to = pods( 'meaning', [
    			'ID' => wp_list_pluck( $meaning->field( 'related_to' ), 'ID' ),
    		] );
    		while( $related_to->fetch() ) {
    
    			echo '<a href="' . esc_url( get_the_permalink( $related_to->field( 'ID' ) ) ) . '">';
    			echo '<div class="related-to-image">' . get_the_post_thumbnail() . '</div>';
    			echo '<div class="related-to-title">' . $related_to->field( 'post_title' ) . '</div>';
    			echo '</a><br/>';
    		}
    
    		echo '</div>';
    
    		return ob_get_clean();
    	}
    );
    • This reply was modified 3 years, 4 months ago by Paul Clark.
    Thread Starter SidianMSJones

    (@sidianmsjones)

    Ok now you touched on something interesting. It did indeed have a bi-directional field with itself and when deselecting it did not relieve the issue however it did change one of the posts being displayed as related. Unfortunately the 4 other posts are not related still.

    I’m trying to wrap my head around this bidirectional thing and whether or not it should be turned on. The meanings posts are meant to be related to one another…if that helps.

    Plugin Support Paul Clark

    (@pdclark)

    Mm… Yes, bidirectional is double-entry meant for when posts are not related to themselves. It wouldn’t be necessary in this case.

    Thread Starter SidianMSJones

    (@sidianmsjones)

    I still haven’t been able to resolve the issue ever after going through your checklist sorry to say. Though I have not yet integrated the PHP.

    Thread Starter SidianMSJones

    (@sidianmsjones)

    Hm, tried the PHP but it just seems to list all Meanings alphabetically. It also would not allow me to limit=”5″.

    Plugin Support Paul Clark

    (@pdclark)

    This version should fix the query and adds a limit of 5.

    add_shortcode(
    	'meaning_related_to',
    	function(){
    		ob_start();
    		// Get this meaning
    		$meaning = pods( 'meaning', get_the_ID() );
    
    		echo '<div class="related-to-list">';
    
    		$limit = 5;
    		$i = 0;
    
    		// Loop through related Meanings.
    		foreach( wp_list_pluck( $meaning->field( 'related_to' ), 'ID' ) as $id ) {
    			$i++;
    			if ( $limit === $i ) {
    				break;
    			}
    
    			$related_to = pods( 'meaning' );
    			$related_to->fetch( $id );
    
    			echo '<a href="' . esc_url( get_the_permalink( $related_to->field( 'ID' ) ) ) . '">';
    			echo '<div class="related-to-image">' . get_the_post_thumbnail( $related_to->field( 'ID' ) ) . '</div>';
    			echo '<div class="related-to-title">' . $related_to->field( 'post_title' ) . '</div>';
    			echo '</a><br/>';
    
    		}
    
    		echo '</div>';
    
    		return ob_get_clean();
    	}
    );
    Thread Starter SidianMSJones

    (@sidianmsjones)

    It works!

    Now, I really apologize, but the reason I was so determined to get the template and shortcodes to work that I already had is because I had finagled so much CSS and such for them to look right (I’m not good at this). AND perhaps more importantly I figured I would be able to replicate the result to create other such “widgets” around the site that I need. Unfortunately with PHP I don’t know how to work with it nearly at all.

    So my question is – did you give me the PHP version because you don’t see how my request could work without it? Are the templates and shortcodes not capable?

    Plugin Support Paul Clark

    (@pdclark)

    The shortcode and template worked for me.
    I usually prefer PHP.
    I sent the PHP because I wasn’t sure why your templates might not be displaying.

    Plugin Support Paul Clark

    (@pdclark)

    P.S. bidirectional field did up being useful here meaning-to-meaning as well

    Thread Starter SidianMSJones

    (@sidianmsjones)

    Are you saying I should keep the bidirectional field on?

    I turned it back on but still the results aren’t related to the post on screen. ??

    Plugin Support Paul Clark

    (@pdclark)

    Yes bidirectional.
    The new shortcode didn’t work?
    Not sure then.
    If neither appear, then would then suspect field naming. E.g., is the field name exactly “related_to” and post type name exactly “meaning”

    Thread Starter SidianMSJones

    (@sidianmsjones)

    Yes it’s those exactly, even the lower casing. Would I be able to pay you to take a look at the back end?

    The new shortcode worked but this will prove impossible for me to replicate over other widgets without learning PHP myself.

    • This reply was modified 3 years, 4 months ago by SidianMSJones.
    Plugin Support Paul Clark

    (@pdclark)

    See https://support.pods.io/chat/ DM or #jobs channel.

    Plugin Author Jory Hogeveen

    (@keraweb)

    Closing topic! Cheers, Jory

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Related posts suddenly stopped working’ is closed to new replies.