Hi @anniesexton
Can you please read over this thread:
http://support.advancedcustomfields.com/forums/topic/reverse-query-relationship-subfield-which-is-nested-in-a-repeater-field/
I think this will provide the solution you are after.
Thanks
E
The issue is most likely that the ‘reference’ field is missing from your import.
Can you please read the update_field
documentation and lean more about this reference.
Next, check that your export / import includes this reference information and that both WP installations use the same field_key’s for the field in question.
Perhaps a better method of export / import is to migrate your DB with DB Migrate Pro
Thanks
E
Hi @tienvijf
Your code looks good.
Have you done any debugging of the data which is queried?
Thanks
E
Hi @Jan
Your english is great, don’t worry about it.
As for your question, yes, this is quite easy.
Firstly, load all the pages via a get_posts
function.
Next, loop over the pages and load the repeater field data foreach page
Lastly, output the repeater data or append it to a global array
Thanks
E
I think @faeronsayn is asking if there is a way to get ACF to recognize existing post_meta on a post and incorporate it/them into a field group assigned to that post.
If so, I’d probably create the new fields and turn to SQL but I’ve been watching this question to see if there is another way (in case I ever spend any significant time updating older pre-ACF-as-religion sites).
I got it working! Here’s my code – just in case someone else finds it useful later on…
<?php // args
$args = array(
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'menu_order name',
'post_type' => 'lesson',
'meta_key' => 'attached_unit',
'meta_value' => get_the_ID()
);
// get results
$the_query = new WP_Query( $args );
// The Loop
?>
<?php if( $the_query->have_posts() ): ?>
<ul>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
<?php wp_reset_query(); ?>
Thanks so much for your help, Elliot! (ACF is simply superb!)
Andy
Solved it. For reference, build the query as if your were querying multiple custom fields. This frees up the ‘meta_key’ option for use in ordering.
Example:
'post_type' => 'post',
'showposts' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'acf_field',
'value' => 'acf_field_value',
'compare' => '='
)
),
'meta_key' => 'acf_number_field',
'orderby' => 'meta_value_num',
'order' => 'ASC'
I just vardumped all of the variables I set to determine if content exists or not:
$statementTrue = get_field( "statement" );
$galleryTrue = get_field("image_gallery");
$videoTrue = get_field("video_content") && get_field("video_embed");
$poetryTrue = get_field("poem_1");
And I got the correct data for statement and gallery but false on the other two.
I doubled checked that the content was posted and that the field names were correct, they were posted and the names are right.
EDIT: I also checked for get_field(“video_content”) and get_field(“video_embed”) separately. They both returned false.
The only way I could get ACF post data to display was to include only the $statementTrue variable. Adding the gallery variable broke it again even though it gave me my content when I vardumped.
Hi @PierreDST
I believe that $uloop->the_post();
is the equivalent of setup_postdata
.
This will override the global post. Int he WP_Query docs, it talks about a function called reset_postdata
. I highly suggest to read over that section.
Thanks
E
Hi @andymacleod
When on the unit
single page, you can load the lessons with a get_posts
function. You can learn more about this here:
http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/
Notes:
1. You do not need to ‘modify’ the loop
2. Use get_posts to load the lessons and loop over them
3. Your meta_query args should find posts where 'post_object_field_name' => get_the_ID()
Thanks
E
Below is the code for posts page. The ‘Hello World’ post has dummy content in each field and has been posted and updated multiple times.
I know it looks like I left out the content and what’s weirder is, while video and poetry content do exist, their tabs are non existent unlike the state and gallery tabs. But while those tabs exist, they’re empty even though there is post data submitted for each content type.
I don’t have any caching plugins installed, could there be a caching setting set by my hosting service by default? I host with ipage.com if that helps.
<?php
get_header();
$idObj = get_category_by_slug('category-name');
$id = $idObj->slug;
$ftimg = wp_get_attachment_url( get_post_thumbnail_id($post->ID));
$statementTrue = get_field( "statement" );
$galleryTrue = get_field("image_gallery");
$videoTrue = get_field("video_embed");
$poetryTrue = get_field("poem_1");
?>
<div id="single">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<div id="tabs">
<section class="post-title" style="background-image: url(<?php echo $ftimg; ?>); background-size: cover; background-position-y: 50%;">
<div id="titleoverlay">
<h1 class="titles title"><?php the_title(); ?></h1>
</div>
<?php include("includes/tabnav.php"); ?>
</section>
<?php if ( $statementTrue == true ) : ?>
<div id="statement-tab">
<?php get_template_part('content', 'statement'); ?>
<div id="social-footer">
<?php include('includes/social-footer.php'); ?>
</div>
</div><!--end statement-tab-->
<?php endif; ?>
<?php if ( $galleryTrue == true ) : ?>
<div id="gallery-tab">
<?php get_template_part('content', 'gallery'); ?>
<div id="social-footer">
<?php include('includes/social-footer.php'); ?>
</div>
</div><!--end gallery-tab-->
<?php endif; ?>
<?php if ( $videoTrue == true ) : ?>
<div id="video-tab">
<?php get_template_part('content', 'video'); ?>
<div id="social-footer">
<?php include('includes/social-footer.php'); ?>
</div>
</div><!--end video-tab-->
<?php endif; ?>
<?php if ( $poetryTrue == true ) : ?>
<div id="poetry-tab">
<?php get_template_part('content', 'poetry'); ?>
</div><!--end-poetry tab-->
<?php endif; ?>
</div>
<?php endwhile; else: ?>
<p class="noposts">Nope. No posts. single.</p>
<?php endif; ?>
<?php get_footer(); ?>
</div>
Thanks for the request. I’ll add this to the to-do and let you know how I go with adding it in.
Cheers
E
Hey. Thanks for your answer. There is definitely more to the story, but I thought it would be a lot to post and possibly irrelevant. I’m not using setup_postdata. Here is the full code for loop-events.php
(I’m using if_single so that I can just load the same loops using get_template_part, but the same problem occurs if I copy the whole loop into the single page)
<div id="event-archive" class="clearfix">
<?php if (is_single()) { $uargs = array( 'post_type' => 'events',
'posts_per_page' => 3,
'meta_key' => 'eventdate', // name of custom field
'orderby' => 'eventdate',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'attending', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
); ?>
<?php
} else {
$uargs = array (
'post_type' => 'events',
'posts_per_page' => -1,
'meta_key' => 'eventdate', // name of custom field
'orderby' => 'meta_value_num',
'order' => 'ASC'
);
}
$uloop = new WP_Query( $uargs ); ?>
<?php while ( $uloop->have_posts() ) : $uloop->the_post();
?>
<?php
$date = get_field('eventdate');
// $date = 19881123 (23/11/1988)
// extract Y,M,D
$y = substr($date, 0, 4);
$m = substr($date, 4, 2);
$d = substr($date, 6, 2);
// create UNIX
$time = strtotime("{$d}-{$m}-{$y}");
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<div id="event-1" class="event">
<div id="event_datestamp"><p class="hdm"><?php echo date('M', $time); ?></p><p class="hdd"><?php echo date('d', $time); ?></p></div>
<?php $eurl = get_field('eventurl'); ?>
<h2 class="event-title"><a href="<?php echo get_permalink($eurl->ID); ?>" title="<?php printf( esc_attr__( 'Read about this event', 'wpzoom' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<span class="att-artists">
<?php
$posts = get_field('attending');
$i = 0;
if( $posts ): ?>
<?php
foreach( $posts as $p ): ?>
<?php
$i++;
?>
<?php
if( $i == 1 )
{
echo '';
}
elseif( $i == count($posts) )
{
echo ', ';
}
elseif( $i > 1 )
{
echo ', ';
}
?>
<a href="<?php echo get_permalink( $p->ID ); ?>" title="See <?php echo get_the_title( $p->ID ). '’s profile'; ?>"><?php echo get_the_title( $p->ID ); ?></a>
<?php endforeach; ?>
<?php endif; ?></span></div>
<div id="event-2" class="event"><div class="eventmeta"><span class="event-meta1"><?php the_field('eventloc'); ?></span>
<span class="event-meta2"><?php echo date('d/m/Y', $time) . ' ('; the_field('age'); echo ')'; ?></span>
</div></div>
<div id="event-3" class="event"><div id="gettick"><span class="event-tkt"><a href="<?php the_field('biturl'); ?>" target="_blank">Book Now</a></span></div></div>
</div>
<?php
endwhile;
?>
</div>
All my loops work fine individually on the single-artist page, and on their individual archive pages. But this, for some reason, can only work once:
'meta_query' => array(
array(
'key' => 'attending', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
'compare' => 'LIKE'
)
)
The fields are correct and I’ve checked so that there are no mistakes with variables etc.
Can you use firebug to determine which element is selected by $("#acf-field-something")
?
Perhaps it is also selecting a google map field, which is then causing the error when ACF can’t find expected DOM elements.
Thanks
E
Hi @navitronic
Thanks for the info.
I think I have figured out the issue.
because you are using a select field to manually set the taxonomy, ACF does not recognize this selected value in the JS.
Then, when you make any change to a taxonomy, ACF’s JS loads up all the selected taxonomy terms and does it’s AJAX request to find metaboxes based on the new location rule data.
ACF does not recognize your select field as a taxonomy term, so it doesn’t include it in the AJAX request. That is why ACF deos not return the correct field groups and your origional group disappears.
To solve this, please change your custom select field to a taxonomy field so that ACF can recognize it!
Hope that helps.
Thanks
E
Hi @augusto
The json shows a correct img tag:
<img src=\"http:\/\/dev\/spa\/wp\/wp-content\/uploads\/2014\/02\/02082_apeacefulscottishevening_2560x1440-120x60.jpg\" \/>
Perhaps the URL is incorrect?
Please make sure the image you are adding to the relationship HTML is vaild.
Thanks
E
Hi @theshae
Something like this should work:
<tr class="<?php if( $x['true_false_field'] ){ echo 'heading'; } ?>">
Hi @Alex.woltz
Can you please explain your request with more detail. It is very hard to understand.
Your title suggest the question is in regards to conditional logic for sub fields? This was added in v4.3.0
Thanks
E
To reply to your first question. There is an issue with your code.
Please change:
$items .= “the_field(‘artist)”;
to
$items .= get_field('artist');
@cleocq – I’ve been trying to do the exact same thing you’re doing, using the Page Builder plugin in combination with Widgets that use ACF. Guess we’ll just have to wait for the widget compatibility with ACF to accomplish this…
Hi Elliot
I saw the ACF GitHUb change you made for the above issue:
https://github.com/elliotcondon/acf/commit/268b02b45110ba27d1da8cdef296d67d5d96a0b2
I’ve tested the fix and can confirm that ACF default field names with an “_” work for single fields, repeater fields, and repeater sub fields.
Thanks for dealing with this so quickly.
Cheers
Hi @shankie
Thanks for the request. This has been pushed to github and will be released soon.
Cheers
E
Hi @vaktmester
Thanks again for the feature request. A new setting for Rows
has been added to the textarea field. Currently, this has been pushed to github and will be released soon.
Cheers
E
Hi @timothy_h
Thanks again for the request. Just wanted to let you know this has made it into the core and will be released soon.
Thanks
E
Ok so I did make a little progress on this.
I set up a second instance of the site on another server to do some further testing.
I was finally able to get it to somewhat work here: http://sandbox.webcontempodata.com/?bedrooms=2
It correctly pulls the data and formats it the way I want it. The only way I could get it to work was by not assigning a custom home page – so that it uses index.php to pull homepage content, and then I added the code from my original apartment finder home page to index.php.
So I guess the main question is: how do I get it to work just like this, but on an interior page like this: http://tlc.mainteractivegroup.com/find-my-apartment/
Also – any idea why I would be getting the PHP error on one site and not on the other when they both are set up the same?
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.