
Ah! We’ll it seems your wp_query that comes after the regular loop overwrites the post object with this: $wp_query->the_post();
You can try putting wp_reset_postdata(); right after the endwhile for that loop.. If that does not work try putting the value in a variable inside the regular loop that comes before the new wp_query and then access the variable where you need it π
hi Jonathan
Thanks for the quick response!
I tried your solution but it still doesnt work.
I put the code in the sidebar section of the template
you can see the page code here:
https://www.dropbox.com/s/2hw4f6g1guvotfh/page-portfolio-col3-sidebar.php
Thanks again
Ronen

Hi @nc
Thanks for the q,
The default value is only loaded on the edit screen. It is not saved automatically when you import data.
Sorry, but this is outside the scope of the ACF plugin.
You will need to write some custom code to hook into each post imported and then update the postmeta manually
Thanks
Elliot

Hi @bigrecreio
Thanks for the code and screenshots, but I don’t understand how your code is possible to work.
You have created a post type, and a custom field which has tags. Is this correct?
This has no relation to a user, so I don’t think your args and the WP_User_Query object would work.
Perhaps you could re explain what you are trying to do.

I can’t recall the function to ‘remove the wp-jquery-ui-dialog’. Can you elaborate on this?

Hi @aaroun@tg
Just to clarify, the issue is if you have a post object field which is marked as required, the post will not save, even if you have selected a post?
Have you checked your console log for any JS errors?

Looks like your loop is a query template. Is this correct?

Hi @BelindaJ
I think you need to re-read my previous advice. I have specified the exact line which needs to be changed. I don’t understand why you have renamed a parameter. this would do nothing.
I am not intending to be rude, but ACF is a developer tool and as a per-requisute you must understand how to use WP actions, filters and an understanding of function paramters, etc.
There’s not much else I can do from my end. I have already given the solution in a previous comment

$value holds an array of rows. It is this array that you save.
All you need to do is loop through the array and modify the row you want, then save the array like normal.
It is the line
$value[] = array("sub_field_1" => "Foo", "sub_field_2" => "Bar");
That ‘adds’ to the array, by removing this, there will be no rows added

Can you please perform some debugging to find the issue?
First save a file (I am to assume this works correctly for the first row)
Now edit your code to print the variable before saving like so:
$field_key = "documents";
$value = get_field($field_key, $post_ID);
echo '<pre>';
print_r(value);
echo '</pre>';
die;
What is the $value?
I think the issue may be fixed by changing $field_key to actually use the field key, not the field name
I am sending screens to assist in troubleshooting.
thank you!




Yes, I have tested that as well, and it is correct. I also used this code to display the values of all the fields:
$fields = get_fields( $post->ID );?>
<pre> <?php var_dump($fields) ?> </pre>
I then compared the output on both the archive page and category pages. Everything is the same except on the archive page, the “photos” field shows an array filled with different photos and sizes, whereas the output on the category pages has a completely empty array.
["photos"]=>
array(0) {
}
Yup, I’m with @shauny. This always felt like a TEC problem and it seems to be more and more clear that it is. However, let’s not quite resolve this thread yet until we’ve got a resolution. Just in case… π
From documentation:
All the API functions can be used with a taxonomy term, however, a second parameter is required to target the term ID. This is similar to passing through a post_id to target a specific post object.
The $post_id needed is a string containing the taxonomy name + the term ID in this format: β$TaxonomyName_$TermIDβ
Examples
Display a field
<p><?php the_field('field_name', 'thetaxonomyname_7'); ?></p>
Hi Elliot – thanks for getting back to me.
Yes, I’ve seen a couple of error in Firebug Console when trying to save a link from a Post in the HTML editor, but here’s the one that relates to ACF:
NS_ERROR_FAILURE: Failure
http://thepooka.org/wp-content/plugins/advanced-custom-fields/js/input.php?ver=4.1.8.1
Line 461
This seems to happen on first attempt to save a link in HTML mode, then I get the following error repeated for each subsequent time I try to save the link:
NS_ERROR_FAILURE: Failure
http://thepooka.org/wp-includes/js/wplink.min.js?ver=3.5.2
Line 1
This is in WP3.5.2 with latest ACF running, but I’ve also experienced the error on WP3.3.1 and on older versions of ACF version 3.
Behaviour when trying to save a link in a post in HTML varies from browser to browser, but can often crash the browser tab altogether.
Any help in resolving this would be appreciated. We use ACF to great effect on a number of sites, but see this issue repeatedly.
Cheers
Marcus

Hi @Needlemouse
Thanks mate.
1. Yes. All field group data will be exported. You can test this yourself
2. Yes. If you remove A field and then update the field group, it will be deleted

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 π

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.
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( __( '← Older posts', 'amplify' ) );
previous_posts_link( __( 'Newer posts →', '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(); ?>

This combination output the label correctly, thanks for the pointers.
<?php
/*
* Displaying a single value's Label
*/
$field = get_field_object('color');
$value = get_field('color');
$label = $field['choices'][ $value ];
?>
Another question on the same issue has raised though. I have a page, with a colorscheme set as described above, also within the page, I have a Repeater Field, which has a sub-field to set a colorscheme.
I’d like to use the same set of color options I’ve set in Options. This works fine if the sub field is named “color”, as this will pick up the choices for a select list. But when these are output, things get confused between the pages colorcheme, and the repeater field box colorscheme – both of which come from a field called “color”.
Is it possible to have a page and a repeater field using the same Options data source for a select list?
Thanks.

You rock π

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!

You’ll need to do a check for $row['description'] before actually echoing the <p> tag – that’s why I placed if( $row['description']) before echo '<p class="description">.... This check will simply make sure that $row['description'] is not empty.
If this doesn’t work for you, PHP can also check for empty values in a number of different ways:
http://php.net/manual/en/function.empty.php
http://php.net/manual/en/function.is-null.php
And there’s a discussion of some implementations over at http://techtalk.virendrachandak.com/php-isset-vs-empty-vs-is_null/ !
Ah, and just for ease of reading: http://diffchecker.com/7za0xnhq π
I figured it out
Code is wrong on 2nd part.
if (($i++ % 2) == 0 ) should be if (($i++ % 2) != 0 )
And one line was missing in the middle $i = 0; rewind_posts();
So in the end, general code is :
<?php
$i = 0;
$rows = get_field('articles_de_presse');
echo '<div class="odd-column">' ;
foreach($rows as $row) {
if (($i++ % 2) == 0 ) {
echo '<div class="actupost"><h3>' . $row['auteur_de_larticle'] . '</h3><div class="actuexeprt">'. $row['contenu_de_larticle'] .' </div></div>';
}
}
echo '</div>' ;
$i = 0; rewind_posts();
$rows = get_field('articles_de_presse');
echo '<div class="even-column">' ;
foreach($rows as $row) {
if (($i++ % 2) != 0 ) {
echo '<div class="actupost"><h3>' . $row['auteur_de_larticle'] . '</h3><div class="actuexeprt">'. $row['contenu_de_larticle'] .' </div></div>';
}
}
echo '</div>' ;?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.