Support » Plugin: IMDb Connector » ACF Repeater field didn’t work imdb_connector_get_movie

  • Resolved Flavia Bernardez

    (@flabernardez)



    Hi Kolja!

    Again your plugin is amazing, but I have a problem I can’t resolve it:

    I’m using ACF for catching imdb id from a CPT. So in one of them, I have a repeater field that saves several imdb movies:

    Example 1

    And this is my code on the template:

     <?php if( have_rows('peliculas') ): ?>
    
                        <ul class="lista">
    
    			            <?php while( have_rows('peliculas') ): the_row();
    
    				            // vars
    				            $spain_title = get_sub_field('titulo_spain');
    				            $movie = get_sub_field('imdb_id');
    				            $movie_imdb = imdb_connector_get_movie($movie);
    
    				            ?>
    
                                <li class="lista-pelicula">
    
                                        <span><?php echo $spain_title ?></span>
                                        <span><?php echo $movie_imdb['title'] ?></span>
    
                                </li>
    
    			            <?php endwhile; ?>
    
                        </ul>
    
    	            <?php endif; ?>
    

    But the info “title original” doesn’t show:

    Example 2

    How can I resolve this? I tried with all the samples in ACF support page: foreach, etc… And I can’t draw the info…

    Thanks so much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author thaikolja

    (@thaikolja)

    This is something that’d take ages to resolve through forums. If you have Slack, please contact me via my Slack name thaikolja in the network wordpress.slack.com, because I have a lot of questions.

    When we’ve found the solution, we’ll post it here so others can benefit from it as well.

    Plugin Author thaikolja

    (@thaikolja)

    After a direct conversation with @flabernardez, we managed to fix it. Here is the new code with comments:

    <?php
    	/** Make sure we get the right rows */
    	the_row();
    
    	/** We read the name of the object containing the repeater field */
    	$parent_field_name = "peliculas";
    
    	/** Now we get all its values */
    	$parent_field_value = get_field( "peliculas" );
    
    	/** We count the values */
    	$parent_field_count = count( $parent_field_value );
    
    	/** We only want to display anything if there's at least one movie entered in the row */
    	if ( $parent_field_count ) {
    
    		/** Now we start to go through the rows */
    		foreach ( $parent_field_value as $field => $value ) {
    			/** We use the IMDb ID as default selector because it's more precise */
    			$selector = $value["imdb_id"];
    
    			/** If there's no IMDb ID entered, we use the Spanish title */
    			if ( ! $selector ) {
    				$selector = $value["titulo_spain"];
    			}
    
    			/** Now we get all the details from the current movie */
    			$movie_details = imdb_connector_get_movie( $selector );
    
    			/** If it fails for some reason, we stop and add an error message to the debug.log file */
    			if ( ! $movie_details ) {
    				error_log( "The entered movie title or IMDb ID did not return any movie." );
    
    				break;
    			}
    			?>
    			<!-- This is how we display the values in HTML -->
    			<ul class="lista-pelicula">
    				<li>
    											<span class="movie-title">
    												<?php echo $movie_details["title"]; ?>
    											</span>
    					<span class="movie-title">
    												<?php echo $movie_details["imdb_id"]; ?>
    											</span>
    				</li>
    			</ul>
    			<?php
    		}
    	}
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘ACF Repeater field didn’t work imdb_connector_get_movie’ is closed to new replies.