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?

  • Sure thing! So, we have a lot of articles. All of them about films. I want to compile a list of those films, ordered by the first letter of each title. Currently I have it set up as follows:

    Underneath the WYSIWYG-editor when writing an article, there’s an ACF for selecting the first letters of each film that appears in the article. When you select the letters, you get text areas into which you type, one row at a time, the names of the films in the text. Example:

    Then I use this data to create a page for each letter on the site that looks like this (the letters at the top link to the other pages but are non-functional for the moment until I lock this down):

    The code for this page looks like this:

    <?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_k',
            'order'=> 'ASC',
            'orderby' => 'elokuvat_k'
    ));
    
    if($posts)
    {
    	echo '<ul>';
    
    	foreach($posts as $post)
    	{
    		echo '<li><a href="' . get_permalink($post->ID) . '">' . get_field($field_name='elokuvat_k', $post->ID) . '</a></li>';
    	}
    
    	echo '</ul>';
    }
    
    ?>
    
    	</div><!--/.pad-->
    	
    </section><!--/.content-->
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    This is all good. However, it becomes a problem if an article has two films in it that begin with the same letter. For example, if I add a film like this:

    Then it will show up like this on the page:

    The problem is that instead of creating two data entries, one of which would be Knock Knock (2015) and the other Kxick Test (2014), it creates a single entity which is known as
    Knock Knock (2015)
    Kxick Test (2014)

    This causes the alphabetical order of that page to become messy, as the lower of these two should be below, in this case, Kummeli V (2014), since it comes later in the alphabet.

    I wanted to know if there is any way to make it so that when entering multiple rows of text into the text area -box, the inputs would create their individual values into the database that the code takes them from, ergo instead of creating this single block of content it would create two separate ones.