Support

Account

Home Forums General Issues error message field type

Solved

error message field type

  • Hi
    I have very limited understanding so please excuse my probably completely naive question. I work for a university research unit. We have a website that has custom fields. Most of these field groups have attachments of some kind – mostly for our reports and publications (pdf and word files). I now get error messages on the website for the attachments e.g. Invalid argument supplied for foreach() in /home/hiaconne/public_html/wp-content/themes/hia-connect/header.php on line 98.
    When I look at the custom fields quite a few of them have an error message under field type “Error Field type does not exist”.
    I think I may have updated the plugin at some stage (now using Version 4.1.0) and I was wandering whether that has caused the problem? I would appreciate any advice anyone can give me. Thanks

  • I saw this error a few times after upgrading from ACF v3 to v4. The previous version of the plugin had the repeater field built in, and it was activated by entering a purchase key… but now (in v4) the repeater field is a separate plugin, downloaded from the store on this site. Other custom fields may behave the same way, like the Options page or the Gallery field.

    You could try to roll back to ACF v3 and see if that fixes your fields – alternatively, purchase and/or download the repeater field from the store and install on your site.

    As a disclaimer, the only reason I mention the repeater field is that your error of invalid argument supplied for foreach() indicates that your site is expecting to loop over an object or array that doesn’t exist, and the repeater field is commonly used in this kind of implementation. I’m not actually sure if you are indeed missing the repeater field, specifically.

  • thanks- okay another naive question – how do I roll back to V3?

  • Check out http://wordpress.org/plugins/advanced-custom-fields/developers/ – you might want to go with 3.5.8, but if that doesn’t work try an earlier one. You will need to replace your existing /wp-content/plugins/advanced-custom-fields/ folder contents with this new plugin. Alternatively, you might be able to delete the plugin from your site’s plugins page and then upload a new version from your hard drive.

    BACK UP YOUR SITE FIRST, both database and files! Lots of things can go wrong here – you don’t want to be caught off-guard. There are lots of backup plugins out there, and your host might offer some sort of backup or restore service as well. Chances are that you will also have to restore your database to a pre-update state as well, as I am fairly sure that there are database chances between ACF v3 and v4. If you don’t have access to your pre-update database, uninstalling ACF from the Plugins page and then re-installing V3 might be your best chance.

    Since you’re working with ACF here, it would be worthwhile to export your field definitions either into PHP or XML, just for safe keeping… you might be able to use these definitions to reset your site if anything goes wrong.

  • Thanks -I’ll give it a go. My only issue is that there is no pre update back up of anything. Someone else set up the website and somehow I have been left administering it with unfortunately no experience or expertise in this. The person who set it up is no longer available to provide support and unfortunately didn’t do any back ups as far as I can tell. I have now backed up everything (hopefully).
    My main concern is to restore functionality to the site – it would be a crappy job re uploading all the information and files but I could cope with that as long as I have a functional site again.
    I’ll let you know how I get on.

  • Okay- I managed to roll back and it worked!!!! Thank you.

    I still have one problem – when I was trying to work out earlier what the problem was I tried changing the field type (this is before your helpful tips so i didn’t know about backing up field definitions though I have at least previously backed up all the files and database for the website). It was just coming up with an error message and so I clicked on ‘file’ in the drop down menu to see whether selecting something would resolve it. Obviously it didn’t. So now that I have rolled back to the older version all the the other custom fields are working except this one. This is the most important one because it was the one which allowed me to attach reports. I tried changing it to ‘repeater’ which seems to have removed the error message on the website. But the function to add an attachment doesn’t come up – strangely I can see what looks to be half images of where the attachments should be even though I can’t see anything when I try and edit the individual report entries. e.g. if you look at http://hiaconnect.edu.au/reports/ and look at the space between the text about the report and the country listing there is a funny line (or two or three depending on how many attachments there once were) which looks like the top of the symbol for a pdf file…
    Any ideas?
    Thanks again for all your help. You are a life saver.

  • Well, we just have to find the right field type. So long as you haven’t updated or saved the posts since the update (fingers crossed!) the field data should still be available if you switch the field back to its old type.

    There may be a hint in the template code. By looking at http://hiaconnect.edu.au/reports/, we can see that the site is reading the post-type-archive or post-type-archive-reports template. Checking out the Template Hierarchy, we can guess that the site is reading a file under the archive.php tree, possibly archive-reports.php. If you open up your theme editor (/wp-admin/theme-editor.php), see if you can find a file named something along those lines… pop that file open and see if you can locate the output for these missing fields.

    If you can’t find the field output in here, keep an eye out for <?php the_excerpt(); ?> or <?php the_content(); ?>, as the missing output may be printed inside a different file such as single.php.

    Looking at the source code of your link, the missing information appears inside a list:

    <ul class="files">
        <li>
            <a href>
            </a>
        </li>
    </ul>
    <p class="meta">...

    So look around for that <ul class="files"> and check out the PHP inside the list that prints your missing field data. Depending on the PHP output, we may be able to figure out what field type it is! Post the code you find if it doesn’t make any sense!

  • Hi again- thanks for your patience. I am not whether I saved or updated but this is what I found-
    archive-reports.php

    <?php
    /**
     * The template for displaying Archive pages.
     *
     * Used to display archive-type pages if nothing more specific matches a query.
     * For example, puts together date-based pages if no date.php file exists.
     *
     * Learn more: http://codex.wordpress.org/Template_Hierarchy
     *
     */
    
    get_header(); ?>
    
    <div id="main_container">
    
    <!-- IE7 float fix --><!--[if lt IE 7]><span class="iefix">.</span><![endif]-->
    
    	<div class="main">
    	
    		<div class="entries_full">
    		
    			<div class="entry_full">
    			
    				<div class="box_twothirds mt30 pr60">
    
    					<?php if (have_posts()) : while ( have_posts() ) : the_post(); ?>
    
    					<?php 
    
    					$country = get_the_term_list( $post->ID, 'report_country','', ', ', '' );
    					$year = get_the_term_list( $post->ID, 'report_year','', ', ', '' );
    					$topics = get_the_term_list( $post->ID, 'report_topic','', ', ', '' );
    
    					?>
    		 
    		 			<?php $count++; if($count > 3) { $count = 1; } ?>
    	 
    					<h4 class="<?php if($count > 1) echo "mt25 "; ?>mb12"><?php the_title(); ?></h4>
    					<?php the_content(); ?>
    					<ul class="files">
    					<?php
    						$rows = get_field('attachments');
    
    						if($rows)
    						{
    							foreach($rows as $row)
    							{
    							?>
    
    							<li>
    								<a href="<?php echo $row['file']; ?>">
    									<?php echo $row['title']; ?>	
    								</a>
    							</li>
    				
    							<?php
    							}
    						}
    					?>
    					</ul>
    					<p class="meta">
    						<?php if($country) echo 'Country: ' . $country . '<br>'; ?>
    						<?php if($year) echo 'Year: ' . $year . '<br>'; ?>
    						<?php if($topics) echo 'Topics: ' . $topics . '<br>'; ?>
    					</p>
    					<div class="bar mt25 mb30"></div>
    					
    					<?php endwhile;
    	  				
    	  				if(function_exists('wp_pagenavi')) { 
    	  					wp_pagenavi(); 
    	  				}
    	 				else { 
    						if (  $wp_query->max_num_pages > 1 ) :
    							next_posts_link( __( '&larr; Older posts', 'amplify' ) );
    							previous_posts_link( __( 'Newer posts &rarr;', 'amplify' ) );
    						endif;
    					}
    					
    					else : ?>
    					<h1><?php _e( 'Not Found', 'amplify' ); ?></h1>
    					<p><?php _e( 'Apologies, but no results were found for that search.', 'amplify' ); ?></p>
    
    					<?php endif; ?>
    
    				</div>
    
    				<!-- Begin Sidebar -->
    				<?php include('sidebar-reports.php'); ?>
    				<!-- end sidebar -->
    						
    				<div class="clear"></div>
    
    			</div><!-- end div.entry -->
    			
    		</div><!-- end div.entries -->
    
    		<div class="clear"></div>
    		
    	</div><!-- end div#main -->
    	
    	<div class="clear"></div>
    	
    </div><!-- end div#main_container-->
    
    <?php get_footer(); ?>

    I also found single-reports.php

    <?php
    /**
     * The Template for displaying all single posts.
     *
     */
    
    get_header(); ?>
    
    <div id="main_container">
    
    <!-- IE7 float fix --><!--[if lt IE 7]><span class="iefix">.</span><![endif]-->
    
    	<div class="main">
    	
    			<div class="entries_full">
    			
    				<div class="entry_full">
    				
    <?php
    $portfolio_cat = get_option('bb_portfolio_cat');
    if($portfolio_cat == 'Choose a category') {$portfolio_cat = 'portfolio';}
    if ( in_category($portfolio_cat) ) {
    include ('portfolio_single.php');
    }
    else {
    ?>
    				
    				<div class="box_twothirds mt30 pr60">
    				
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    				<?php 
    
    					$country = get_the_term_list( $post->ID, 'report_country','', ', ', '' );
    					$year = get_the_term_list( $post->ID, 'report_year','', ', ', '' );
    					$topics = get_the_term_list( $post->ID, 'report_topic','', ', ', '' );
    
    					?>
    		 
    		 			<?php $count++; if($count > 3) { $count = 1; } ?>
    	 
    					<h4 class="<?php if($count > 1) echo "mt25 "; ?>mb12"><?php the_title(); ?></h4>
    					<?php the_content(); ?>
    					<ul class="files">
    					<?php
    						$rows = get_field('attachments');
    
    						if($rows)
    						{
    							foreach($rows as $row)
    							{
    							?>
    
    							<li>
    								<a>">
    									<?php echo $row['title']; ?>	
    								</a>
    							</li>
    				
    							<?php
    							}
    						}
    					?>
    					</ul>
    					<p class="meta">
    						<?php if($country) echo 'Country: ' . $country . '<br>'; ?>
    						<?php if($year) echo 'Year: ' . $year . '<br>'; ?>
    						<?php if($topics) echo 'Topics: ' . $topics . '<br>'; ?>
    					</p>
    					<div class="bar mt25 mb30"></div>
    				
    <?php endwhile; // end of the loop. ?>
    
    				</div>
    
    <!-- Begin Sidebar -->
    <?php include('sidebar-reports.php'); ?>
    <!-- end sidebar -->
    							
    				<div class="clear"></div>
    				
    <?php } ?>	<!-- end single post content -->
    
    				</div><!-- end div.entry -->
    				
    			</div><!-- end div.entries -->
    
    	<div class="clear"></div>
    		
    	</div><!-- end div#main -->
    	
    	<div class="clear"></div>
    	
    </div><!-- end div#main_container-->
    
    <?php get_footer(); ?>
  • Phew, that’s quite a dump… for future use, check out http://pastebin.com/, it’s a bit more dump-friendly and it will format a bit easier 🙂

    Good news – we know that the field name you are looking for is called attachments, and it’s looking for two items inside called “file” and “title”. I can emulate this setup using a repeater with 2 sub-fields inside named “File” and “Title”!

    Why don’t you try setting up two text fields inside a repeater and see what happens? I’ve attached a screenshot of what this might look like, though I’m working with v4 so it may differ a bit from your view.

  • sorry- another newbie mistake.
    I think I love you! It works!!!!!
    I had to fiddle with a few bits (change file type to file and change return value to file url and also add a rule to make it work the right post types).

    Thank you so much for all your patience and help and putting up with all my silly mistakes. I have learned a lot.

  • This reply has been marked as private.
  • Yessss!! Nice work, great to see that patched up.

    The best way to proceed with updates in the future is to upgrade to ACF v4 and purchase the Repeater Field plugin – the upgrade doesn’t require any work, just update as normal and install/enable the repeater field.

    However, for now you may wish to stick with v3 until the rest of the site is stable. If that’s the case, you’ll want to avoid updating ACF, so to make sure that nobody hits that button by accident you can drop this code into the main ACF plugin file:

    add_filter('site_transient_update_plugins', 'c15465_remove_update_nag');
    function c15465_remove_update_nag($value) {
     unset($value->response[ plugin_basename(__FILE__) ]);
     return $value;
    }

    This is certainly not a good permanent solution, but it might spare you some grief in the near future.

    Oh, and here… http://www.advancedcustomfields.com/add-ons/repeater-field/. It’s a tiny one-time purchase and you can use it on as many sites as you want! Plugins like this and their devoted developers (@elliot) are well worth supporting (in my opinion).

    Good luck out there 🙂

  • Thanks again – I am feeling soo happy to have this sorted
    I think I’ll breathe deeply- give it a few days to make sure I have everything functioning on the site and then I’ll upgrade and purchase the repeater field plugin. In the meantime I’ll do as you suggest to avoid accidental updates…

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

The topic ‘error message field type’ is closed to new replies.