Support

Account

Home Forums Backend Issues (wp-admin) Can I use the text area to generate multiple meta values? Reply To: Can I use the text area to generate multiple meta values?

  • Hi, with some help from WP.org I managed to sort this out yesterday. For the record, the final code that we ended up using is the following:

    
    text/x-generic page-10787.php 
    PHP script text
    <?php get_header(); ?>
    
    <section class="content">
    
    	<?php get_template_part('inc/page-title'); ?>
    
           <div class="pad group">
    
    <div class="entry">
    						<div class="entry-inner">
    							<?php the_content(); ?>
    							<?php wp_link_pages(array('before'=>'<div class="post-pages">'.__('Pages:','hueman'),'after'=>'</div>')); ?>
    						</div>
    						<div class="clear"></div>
    					</div><!--/.entry-->
    
    <?php
    
    $posts = get_posts( array(
        'numberposts' => -1,
        'meta_key' => 'elokuvat_l',
        'order'=> 'ASC'
    ) );
    
    if( $posts ) {
    	echo '<ul>';
    		$temporary_list = array();
    		foreach( $posts as $post ) {
    			$film_names = get_field( 'elokuvat_l', $post->ID );
    			$film_names_array = preg_split( '/\r\n|\r|\n/', $film_names );
    			foreach( $film_names_array as $film_name ) {
    				$temporary_list[] = array( 'post_id' => $post->ID, 'film_name' => $film_name );
    			}
    		}
    		// custom sort function
    		usort( $temporary_list, function ( $a, $b ) {
    			return strcasecmp($a['film_name'], $b['film_name']); // compare two strings ignoring case
    		});
    		// loop and display
    		foreach( $temporary_list as $film_name ){
    			echo '<li><a href="' . get_permalink($film_name['post_id']) . '">' . $film_name['film_name'] . '</a></li>';
    		}
    	echo '</ul>';
    }
    
    ?>
    
    	</div><!--/.pad-->
    
    </section><!--/.content-->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>