Support

Account

Home Forums General Issues Post Object: get_post_meta

Solved

Post Object: get_post_meta

  • Hello all,

    Hoping I can get some help with this.

    I’m working with this plugin called Cr3ativ Conference
    https://wordpress.org/plugins/cr3ativ-conference/

    I have now created a new Custom Post Type called Films, that has a Post Object ACF for one of these conference sessions.

    These sessions include a dropdown select for Speakers.

    For my Speakers list, I’m using the same bit of code that this plugin uses for the speakers list. Thumbnail and Title get pulled in correctly, except for the permalink, it keeps giving me the current pages permalink.

    Have tried a number of things but can’t figure it out.

    Can share more but here’s the speakers list section.

    `

    
    
    <!-- Start of speaker list -->
    <div class="speaker_list">
    <?php
    $cr3ativ_confspeakers = get_post_meta($post->ID, 'cr3ativ_confspeaker', $single = true);
    ?>
    <?php
    if ( $cr3ativ_confspeakers ) {
    
    foreach ( $cr3ativ_confspeakers as $cr3ativ_confspeaker ) :
    
    $speaker = get_post($cr3ativ_confspeaker);
    $speakerlink = get_permalink( $speaker->ID );
    echo get_permalink( $speaker->ID );
    echo'<div class="speaker_list_wrapper">';
    echo '[url=]';
    echo get_the_post_thumbnail($speaker->ID). '<div class="redact redact__small">' . $speaker->post_title .'</div></div>';
    
    endforeach;
    
    } ?>
    </div><!-- End of speaker list -->

    `

    Hope yall can help.

  • Hi @thehonestape

    Could you please make sure that the $speaker->ID has the correct ID?

    Also, it seems the issue is not related to ACF. Could you please get it touch with the Cr3ativ Conference author instead?

    If you still think that this is related to ACF, could you please share some screenshots of the issue and the setup you have?

    Thanks 🙂

  • Hey James, let me clarify why I thought this might be related to ACF.

    
    
    					<?php
    						$post_object = get_field('film_session');
    
    						if( $post_object ):
    
    						// override $post
    						$post = $post_object;
    						setup_postdata( $post );
    					?>
    
    					<?php
    						$cr3ativconfmeetingdate = get_post_meta($post->ID, 'cr3ativconfmeetingdate', $single = true);
    						$confstarttime = get_post_meta($post->ID, 'cr3ativ_confstarttime', $single = true);
    						$confendtime = get_post_meta($post->ID, 'cr3ativ_confendtime', $single = true);
    						$confdisplaystarttime = get_post_meta($post->ID, 'cr3ativ_confdisplaystarttime', $single = true);
    						$confdisplayendtime = get_post_meta($post->ID, 'cr3ativ_confdisplayendtime', $single = true);
    						$cr3ativ_confspeakers = get_post_meta($post->ID, 'cr3ativ_confspeaker', $single = true); 
    						/* ACF Fields Within Session */
    						$ticket_link = get_field('ticket_link');
    					?>
    
    					<div class="speaker_list">
    					<?php
    					 $cr3ativ_confspeakers = get_post_meta($post->ID, 'cr3ativ_confspeaker', $single = true);
    					?>
    					<?php
    						if ( $cr3ativ_confspeakers ) {
    
    							foreach ( $cr3ativ_confspeakers as $cr3ativ_confspeaker ) :
    
    								/* What I had to hack for this to somewhat wark, but title must match */
    								$speaker = get_post($cr3ativ_confspeaker);
    							 	echo'<div class="speaker_list_wrapper">';
    								$speakerlink = sanitize_title_with_dashes($speaker->post_title);
    								echo '<a href=' . '/speaker/' . $speakerlink . '>';
    								echo get_the_post_thumbnail($speaker->ID). '<div class="redact redact__small">' . $speaker->post_title .'</div></a></div>';
    								/*-- End workaround
    
    								/* How it usually work on their templates 
    								$speaker = get_post($cr3ativ_confspeaker);
    	              $speakerlink = get_permalink( $speaker->ID ); // Permalink returning current page URL 
    	              echo'<div class="speaker_list_wrapper">';
    								echo '<a href="'. $speakerlink .'">';
    		        		echo get_the_post_thumbnail($speaker->ID). '<div class="redact redact__small">' . $speaker->post_title .'</div></a></div>';
    								*/
    
    							endforeach;
    
    					} ?>
    					</div><!-- End of speaker list -->
    
    					<?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
    					<?php endif; ?>
    

    I thought maybe I was ending the post object call wrong?

    Everything else works for the speakers list (thumbnail, post_title) just not the permalink.

    Abe

  • Hi @thehonestape

    The problem is that you are trying to get the permalink of the Cr3ativ Conference’s post object:

    $cr3ativ_confspeakers = get_post_meta($post->ID, 'cr3ativ_confspeaker', $single = true);
    $speaker = get_post($cr3ativ_confspeaker);
    $speakerlink = get_permalink( $speaker->ID );

    Which is not related to ACF at all. On the other hand, the code to get the post object is executed correctly:

    $post_object = get_field('film_session');

    This means that ACF is working correctly, but there’s something wrong with how you get the Cr3ativ Conference’s post object. I suspect there’s something wrong with the speaker ID:

    get_permalink( $speaker->ID );

    But it also could be anything else. For further and better support, I suggest you contact Cr3ativ Conference author instead.

    I hope this makes sense 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.