Thank you very much Jonathan,
your response helped me a lot.
Here is the code i’ve added in function.php and it runs fine:
function my_relationship_query( $args, $field, $post )
{
$args["meta_key"]="show_in_news";
$args["meta_value"]="1";
return $args;
}
// filter for a specific field based on it's name
add_filter('acf/fields/relationship/query/name=related_articles', 'my_relationship_query', 10, 3);

Hi Steve,
You can’t do what you’re asking just by modifying the wp_query with pre_get_posts.. Atleast not by querying artwork.
However, you can instead of directly querying artwork and trying to order those query the artists.
So you would do a custom wp_query for all artists and order them by their lastname like so:
$args = array(
'post_type' => 'artist',
'orderby' => 'meta_value',
'meta_key' => 'surname',
'posts_per_page' => -1
);
Then as you loop through each artist you query their artwork (inside the artist loop).
$artist_ID = get_the_ID();
$artwork_args = array(
'post_type' => 'artwork',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'artist_dropdown',
'value' => $artist_ID,
'compare' => '='
)
)
);

Hi @groberts
Yes ACF isn’t a querying motor in any way really so sure, anything you can do with wp_query you can use ACF for. Everything else and as advanced as that query you’ll have to do it yourself.
Feel free to mark your second post as the answer so we know this topic is closed π
Thanks Jonathan,
I thought to use conditional logic for this, but i am not able to find if i could do using this.
If only using jquery validation this is possible then, i will do the needful.
Thanks for your quick support.

Hi @architbjoshi,
I’m guessing by start date and end date fields you’re referring to two date fields you’ve created.
Unfortunately there’s no such logic built into ACF.
Your only option is to insert your own script on your admin page with which you update the datepicker options.
You can use this filter to add your custom script file:
http://www.advancedcustomfields.com/resources/acfinputadmin_enqueue_scripts/
And then you’ll need to check when either start or end date input has been changed and modify the other field accordingly.
//To set a minimum date (back in time)
jQuery( '.acf-field-UNIQUEID .acf-date_picker input.input' ).datepicker( 'option', 'minDate', date.format() );
//To set a maximum date (forward in time)
jQuery( '.acf-field-UNIQUEID .acf-date_picker input.input' ).datepicker( 'option', 'maxDate', date.format() );

Hi @cdiscla,
Assuming you use the relationship field for selecting the posts you can use this filter to modify the query to only fetch posts with show_in_news set to 1/true:
http://www.advancedcustomfields.com/resources/acf-fields-relationship-query/

Hi @manooweb
Thanks for the update.
Did you hear back from OVH about the question:
I asked again to OVH a way for knowing why I canβt connect to ACF host with CURL call in WordPress API.
Do all other plugin updates work correctly in your WP install?
I am loving ACF5 and acf-qtranslate plugins thanks all involved.
I am having the same issue where the the repeater and even the flexable content – does not want to update when the post is saved – it renders blank.
I have the following versions and I am working on a local MAMP PRO installation.
Wordpress – (4.2.2)
ACF5 Pro: – (5.2.6)
acf-qtranslate: – (1.7.9)
qTranslate X – (3.3)
PHP – (5.6.7)
Chrome – (43.0.2357.124)
Anything I can try?
Thanks in Advance.
My search page code is :
<div class="row">
<?php
$loop = new WP_Query( array(
'post_type' => 'events','posts_per_page' => -1, 'order=ASC' )
);
if ($loop->have_posts() ):
while ( $loop->have_posts() ) : $loop->the_post();
get_template_part( 'loop');
endwhile;
else :
get_template_part( 'loop', 'empty' );
endif;?>
</div>
and loop.php content code is (for example) :
<article id="post-<?php the_ID(); ?>">
<div class="card">
<div class="card-image">
<?php
$image = get_field('event_cover');
if( !empty($image) ): ?>
<img src="<?php echo $image['sizes']['medium'] ?>"/>
<?php endif; ?>
</div>
</div>
</article>
This exact same snippet works for displaying the image of all posts in all pages…but not on search page π
And 302 is the good ID (I mean, the ID of the image that should be displayed…).
Thanks for your time and help John π
EDIT: some more details that may help.
1) I have a taxonomy field named “event_style”. When I filter posts by this custom field it works great (The image is displayed correctly). It fails only when I use the distance filter to modify the query…
2) I have another image field displayed (as an object) in the header (so it’s outside the loop). This one doesn’t work neither when posts are filtered by distance. Works well on other pages.

I know these may sound like an obvious questions, but the code you have for displaying the images appears that it should be working.
Is code is in “The Loop” of the search results page?
Check to be sure that there is actually an attachment post with the post ID of 302 and that it is an image. This could cause the ID to be returned instead of the image array.
Also, rather then if( !empty($image) ): you could do if (is_array($image)): This would be a better test.
hi John, thanks for answering.
I have a template part named ‘loop.php’, which I use to display all loops in my application.
In this file I use the following code to display image from custom field:
<?php
$image = get_field('event_cover');
if( !empty($image) ):
?>
<img src="<?php echo $image['sizes']['medium'] ?>" alt="<?php echo $image['alt']; ?>" />
<?php endif; ?>
$image gets an array of values (as expected) in all pages, but not in search results page if posts are filtered by distance… it gets a string value instead.
Not sure if I’m clear… sorry

Why not just ask your questions here, it’s free.
Just explain the problem clearly, code and screen shots usually help.
Post one question per topic.
~JH

A relationship field stores an array of post IDs. Try
'meta_query' => array(
array(
'key' => 'project',
'value' => '"'.$post->ID.'"',
'compare' => 'LIKE'
)
)

Thanks for the feature request. This is something that’s actually been requested often. I can’t speak for the developer but I know that this is one of those things in WP that’s easier said than done. I’ll pass the request on to the dev.

Don’t know if you’ve thought about this, but this is a perfect candidate for a custom post type and custom taxonomies. This is a good plugin for creating them: https://wordpress.org/plugins/custom-post-type-ui/
Then you can have one or more custom taxonomies for your categories and it becomes quite a bit simpler to maintain than putting this in either pages or posts. Custom post types and taxonomies can also have their own templates that are automatically used by WP, so then there is no need to the admin to select a special page template to use for a category or a product.

You would need to create custom JavaScript for the field in question, make an AJAX request and do your own query for the select2 field of the taxonomy field. This isn’t something that you can to with ACF. You can start here: http://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/
Another way you could do this is to use a regular select field that you dynamically populate from the first taxonomy then create a conditional select fields that show/hide based on the selection of the first select field. A bit complicated to build.

Your meta_query is a bit off I think, the second meta_query is overriding the second.
$posts = get_posts(
array(
'post_type' => 'event',
'posts_per_page' => -1,
'meta_key' => 'event_date',
'orderby' => 'meta_value_num',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'event_date',
'compare' => '>',
'value' => $today,
'type' => 'DATE',
),
array(
'key' => 'instructors',
'value' => $instructor,
'compare' =>'IN',
),
)
),
);

Hi,
If you have a select field without multiple select it should just return a value not an array..
This code might get you in the right direction:
<?php
$activity_rating = get_field('activity_rating');
switch($activity_rating){
case '1':
$img = 'urltoimage';
break;
case '2':
$img = 'urltoimage2';
break;
case '3':
$img = 'urltoimage3';
break;
case '4':
$img = 'urltoimage4';
break;
case '5':
$img = 'urltoimage5';
break;
case default:
$img = 'fallbackimage';
break;
echo '<img src="' . $img . '" alt="" />';
}
?>

Hi @powcom,
Natively the answer is no. There’s no way to do that.
However you could create your own plugin for this.
Create a custom admin page. In it you do a wp_query for all posts (or any post type) which contains the data you want to be able to edit. Output them as a table list with the inputs you need (this could get tricky if you have many different field types but if it’s just inputs, editors etc. it would be fairly simple. Then on posting your custom form table just do the logic necessary to update each posts information.
I think this would be a pretty great idea for a third party plugin. The biggest issue that I can think of is how to make it dynamic.. One would probably want to be able to set in some settings which field groups to do the wp_query on or maybe do it dynamically on the custom admin page before the wp_query even runs.

Hi,
Are the second image of the field group admin?
There are quicklinks for the necessary actions in the latest versions of ACF.
actions like “view” and “quick edit” are not applicable to field groups but they have a delete action and an regular edit action.

Hi @rkeefer
Here’s how you would do this based on the code you’ve provided
elseif( get_row_layout() == 'quotes_slider' ):
$heading = get_sub_field('heading');
$quotes = get_sub_field('quotes');
?>
<div class="ctaContent ctaContent1 ctaTestimonials clearfix">
<h3><?php echo $heading; ?></h3>
<div class="flexslider" id="testimonialsSlider1">
<ul class="slides">
<?php foreach($quotes as $quote): ?>
<li>
<?php echo $quote['subfieldname']; ?>
</li>
<?php endforeach; ?>
</ul>
</div><!-- #testimonialsSlider1 -->
</div>
<?php endif; ?>
Good luck!
EDIT: Actually what ended up happening was as I was changing some varaibles I misspelled one of them.
After looking over everything it seems that my get_posts is not returning anything in the array and is NULL.
<?php
$teamLeaders = get_posts(array(
'post_type' => 'mro_volunteer',
'meta_query' => array(
array(
'key' => 'assigned_project', // name of custom field
'value' => '"' . get_the_ID() . '"', // matches exaclty
'compare' => 'LIKE'
)
)
));
?>
This is the correct post type and correct key, I checked the volunteers that are published and they all have the project in question assigned to them through the relationship field. I’m not sure why it can’t query them. It’s limited to only one if that makes any difference.
Hi @jonathan I really appreciate the input. You solution/work around makes sense but I am a little concerned because I feel like I may be putting a bandaid on the submit to repeater since it’s not truly supported.
I may handle this a little different than I originally planned since there are going to be 1000s of posts each with up to 20 repeater rows per-post. I think I may create a post type to store the actual location data (what I am calling sightings). I can then create a relationship between the listings post type and the sightings post type. I should be able to then query everything as needed. Thanks for the help.
You can’t include ACF field in csv import, you have to add this functionality in plugin.
You don’t need field id generated by ACF to use meta values. Just call WP_User_Query with a meta_query.

Hi Greenhoe,
I don’t think you can easily update the taxonomy parameter of your field once the edit screen has been rendered. It would require an AJAX call and recreating the entire field dynamically..
May I suggest a different solution that’s maybe a bit easier and doable.
If you use a relationship field instead there’s a built in filter capability for taxonomies. You can set the field to only allow for 1 value so that it’ll work pretty much the same as the post_object field.
Then if you really want you should be able to create some custom Javascript for the extra functionality. Look for a change in the taxonomy dropdown and change the taxonomy filter dropdown in the relationship field accordingly. It should trigger the filtering automatically. If you also want to make sure the client can’t change the filter themselves you could just add a tiny CSS snippet to hide the taxonomy filter from them.
What do you think?
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.