Hi Elliot,
I’ve been having a look and don’t know if I’ve got something wrong with it but can’t access the global $current_screen, get_current_screen() returns null and the $_GET array is empty when I run them from within the filter. The $post term passed to the filter is also null.
I’m going round in circles a bit here.
function mo_acf_available_posts( $args, $field, $post )
{
global $wp_query;
global $page_now;
$term = '1'; // WORK OUT HOW TO GET ACTIVE TERM
$args['client'] = $term;
var_dump($args);
echo "<hr>";
var_dump($field);
echo "<hr>";
var_dump($wp_query);
echo "<hr>";
var_dump($page_now);
echo "<hr>";
var_dump($_GET);
echo "<hr>";
return $args;
}
//add_filter('acf/fields/post_object/query/name=excluded_projects', 'mo_acf_available_posts', 10, 3);
This filters the posts by the client term id=1, I just need to get the current term ID and exchange the hard-coded 1 in.
Here’s the vars dumped by the server for each:
$args:
array(7) { ["numberposts"]=> int(-1) ["post_type"]=> string(7) "project" ["orderby"]=> string(5) "title" ["order"]=> string(3) "ASC" ["post_status"]=> array(5) { [0]=> string(7) "publish" [1]=> string(7) "private" [2]=> string(5) "draft" [3]=> string(7) "inherit" [4]=> string(6) "future" } ["suppress_filters"]=> bool(false) ["client"]=> string(1) "1" }
$field:
array(18) { ["key"]=> string(19) "field_52f3bb5c778f0" ["label"]=> string(17) "Excluded Projects" ["name"]=> string(27) "fields[field_52f3bb5c778f0]" ["_name"]=> string(17) "excluded_projects" ["type"]=> string(6) "select" ["order_no"]=> int(1) ["instructions"]=> string(0) "" ["required"]=> int(1) ["id"]=> string(27) "acf-field-excluded_projects" ["class"]=> string(11) "post_object" ["conditional_logic"]=> array(3) { ["status"]=> int(1) ["rules"]=> array(1) { [0]=> array(3) { ["field"]=> string(19) "field_52f3b64ed5d5c" ["operator"]=> string(2) "==" ["value"]=> string(1) "1" } } ["allorany"]=> string(3) "all" } ["post_type"]=> array(1) { [0]=> string(7) "project" } ["taxonomy"]=> array(1) { [0]=> string(3) "all" } ["allow_null"]=> int(0) ["multiple"]=> int(1) ["field_group"]=> int(149) ["value"]=> string(0) "" ["choices"]=> array(0) { } }
$wp_query:
object(WP_Query)#158 (51) { ["query"]=> NULL ["query_vars"]=> array(0) { } ["tax_query"]=> NULL ["meta_query"]=> bool(false) ["date_query"]=> bool(false) ["queried_object"]=> NULL ["queried_object_id"]=> NULL ["request"]=> NULL ["posts"]=> NULL ["post_count"]=> int(0) ["current_post"]=> int(-1) ["in_the_loop"]=> bool(false) ["post"]=> NULL ["comments"]=> NULL ["comment_count"]=> int(0) ["current_comment"]=> int(-1) ["comment"]=> NULL ["found_posts"]=> int(0) ["max_num_pages"]=> int(0) ["max_num_comment_pages"]=> int(0) ["is_single"]=> bool(false) ["is_preview"]=> bool(false) ["is_page"]=> bool(false) ["is_archive"]=> bool(false) ["is_date"]=> bool(false) ["is_year"]=> bool(false) ["is_month"]=> bool(false) ["is_day"]=> bool(false) ["is_time"]=> bool(false) ["is_author"]=> bool(false) ["is_category"]=> bool(false) ["is_tag"]=> bool(false) ["is_tax"]=> bool(false) ["is_search"]=> bool(false) ["is_feed"]=> bool(false) ["is_comment_feed"]=> bool(false) ["is_trackback"]=> bool(false) ["is_home"]=> bool(false) ["is_404"]=> bool(false) ["is_comments_popup"]=> bool(false) ["is_paged"]=> bool(false) ["is_admin"]=> bool(false) ["is_attachment"]=> bool(false) ["is_singular"]=> bool(false) ["is_robots"]=> bool(false) ["is_posts_page"]=> bool(false) ["is_post_type_archive"]=> bool(false) ["query_vars_hash"]=> bool(false) ["query_vars_changed"]=> bool(true) ["thumbnails_cached"]=> bool(false) ["stopwords":"WP_Query":private]=> NULL }
This doesn’t look right, lots of false values and no information, think this might be why I can’t get the $_GET var.
$pagenow:
NULL
$_GET:
array(0) { }
I may well be doing something stupid here but thought I’d post up the code in case someone else can see what I need to do, any advice would be great. Thanks,
Danny

Hi @Till
Thanks for the bug report. The line in question is modifying the WP media object.
I haven’t seen this error before, so I will assume for now that it is server specific.
Are you able to setup a local environment to test a blank WP install with ACF?
Thanks
E
I guess what I’m asking is where in your plugin is the HTML I can see when looking at my post page with my text field on created.
I’d like to add:
onblur="myFunction()"
to this HTML created by ACF
<input type="text" id="acf-field-miles" class="text" name="fields[field_52f526e67d916]" value="8000" placeholder="e.g 10,000" testing="">
Is it line 79 in text.php?
I can’t seem to work out where exactly that is created. Sorry 🙁
Ok thanks.
I just meant an onblur event , opposite of onfocus. So when the user tabs out of a field. Not an actual blur effect.
The conversion and coding are quite straight forward, I’m just no clear where I’d put the code as it’s being created by ACF.
Here’s a version of what I mean. Fill in the miles tab to the Kilometres and it auto fills.
Would you be able to suggest where or what I might target using the ACF plugin?
Thanks again.

Hi @Will
If $internals is an array of posts, then the get_sub_field function is working correctly. Perhaps the issue lies in the setup_postdata funciton which can cause many problems wiht the global $post object.
Try this instead:
$internals = get_sub_field('internal_link');
foreach($internals as $p): ?>
<a href="<?php echo get_permalink( $p->ID ); ?>">

Hi @sja
ACF does not offer this kind of functionality, however, you can easily add some custom jQuery to the page.
jQuery can be used to add events to elements such as blur.
Further questions regarding this matter would be best asked on a stackoverflow forum, as many web developers are actively posting code and solutions for jQuery.
Thanks
E

Hi @pastore1980
You can perform a meta_query on a ‘multi-value’ field by using a LIKE parameter.
Here is an example (last example on page):
http://www.advancedcustomfields.com/resources/field-types/checkbox/
Thanks
E
[quick update post-debug]
this is my array before $field
Array
(
[choices] => Array
(
[home] => Homepage
[servizi] => Servizi
)
)
(Results are correct)
@elliot I did. Whether I use 50 or 200 doesn’t matter. If I leave the function out (which means it is querying six thousand posts) it works just fine but anything I do to try to reduce that numbers breaks it
Hi, thank you for your support.
For your questions:
1) yes
2) yes
3) yes
However, this code works!
<?php
$zone_articoli = get_field('zona_per_i_pacchetti');
$args = array(
'post_type'=>'pacchetto',
'meta_key'=>'zona_per_gli_articoli',
'meta_value'=>$zone_articoli
);
$loop = new WP_Query($args);
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php endwhile; wp_reset_postdata();?>
A last question:
If i want use a multiple select for a field, how i can do it?
The field that i want use is ‘zona_per_gli_articoli’
Thank you so much for your help!

Hi @andisaleh and @elliot
I feel this is getting closer but still can’t work out why such a simple task of grabbing one value from another post and matching it to current post is so hard. I am going crazy! haha.
New query is now this, but unfortunately it returns nothing.
<?php
$args = array(
'numberposts'=> -1, // Fetch all posts...
'post_type'=> 'release', // from the 'release' CPT...
'meta_key' => 'artist_name', // which inside this meta key...
'meta_value' => get_the_ID(), // has this meta value.
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) :
echo '<ul>';
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li>
<img src="<?php the_field('cover_image'); ?>" />
<?php the_field('artist_name'); ?>
<?php the_title(); ?>
</li>
<?php
endwhile; echo '</ul>';
endif; wp_reset_query(); ?>
Failing this – do either of you know any quick places I can go to pay someone to do this? I just don’t have any contacts in that regard.

Hi @andisaleh
The meta_value should be the value which is saved, which in this case is the ID, not the title.
So, you should change the_title() to get_the_ID()
This will then query posts of post_type release where the selected artist is the current artist being viewed.
Thanks
E

Hi @andisaleh
Thanks for the explanation, but that now outputs ALL of the releases. Which makes it no different to my original post/query which outputs everything.
How do I get it to recognize what artist page i am on and then ONLY output releases from that artists. Right now it is just bringing in every release from every artist on every page.
Does that make sense?

I totally understand that.nothing worse than cutting a feature many people use. but i only ask myself one question. what image size is wordpress actually using if you select e.g. thumbnail even if it is unset in the functions.php. e.g. the preview size was set by default to thumbnail on my side and the image size used looked much much bigger than the thumbnail size i would have expected. i just rechecked it. if you set the preview size to thumbnail and it is unset acf and wordpress use the full size instead. same procedure if you use medium or large. always the full version is used instead of the unset one.
Here’s a step-by-step.
1. Find a way to get the artist’s name. It’s stored as the post’s title. Great. We can grab it with the_title().
2. Find where the artist is declared in the ‘release’ CPT. It’s inside a custom field named album_artist. Custom fields are stored inside meta keys.
3. Construct a query with these values and spit out the results. You get:
<?php
$args = array(
'numberposts'=> -1, // Fetch all posts...
'post_type'=> 'release', // from the 'release' CPT...
'meta_key' => 'album_artist', // which inside this meta key...
'meta_value' => the_title() // has this meta value.
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) :
echo '<ul>';
while ($my_query->have_posts()) : $my_query->the_post();
?>
<li><?php the_field('album_title') ?></li>
<?php
endwhile; echo '</ul>';
endif; wp_reset_query(); ?>
Hope that helped.

Hi @lowercase
Your code is failing to recognize the importance of the meta_query argumnet:
http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values/
Thanks
E

Hi @pastore1980
To clarify:
1. The above code is used int he single.php template (view for a post)
2. The filter value is loaded via $zone_articoli = get_field('zona_per_i_pacchetti');
3. The $loop find all pacchetto and ignores the filter
Perhaps you need to debug your code. Try removing the $zone_articoli from the equation and hard code the meta_query.
Also, is the select field a single or multi select?
Thanks
E

Hi @megancm
Your last reply is quite vague. Which array are you talking about?
The above code was to help you see visually that the loop is working correctly.
The array variable printed out is the selected relationship items/ Yes, these should be different, shouldn’t they?
Please look at the outputted data and determine if the data is correct, or if it is not.
Thanks
E

Hi @BeeBlu
I just noticed the problem!
Change:
<img src="<?php echo $images[0]["url"]["large"]; ?>" >
To
<img src="<?php echo $images[0]["sizes"]["large"]; ?>" >
Remember to always debug your code, and read the docs.
Thanks
E

Hi @BeeBlu
This debug info prooves that the images are being loaded. So you can use this in your code as you previous had:
<?php
$images = get_field('gallery');
?>
<!-- Image here -->
<img src="<?php echo $images[0]["url"]["large"]; ?>" >

Hi @edwin
I think you can edit the global $wp_query object to modify the number of results and the actual results found.
But perhaps the easiest solution of all is to use a taxonomy for the ‘status’ this way you can separate it form the meta_query.
Thanks
E

Hi @Exelmans Graphics
The biggest hurdle for this feature is getting it to work with a multi-select field. I just can’t see a way to include an edit button for each item.
Sorry, but thanks for the request.
Thanks
E

Hi @faeronsayn
Sorry, but I don’t fully understand your question.
Now I want these fields to appear on their post edit pages using ACF. How can I do this?
Please be very descriptive and clear.
Thanks
E

Hi @andisaleh
Thanks for your reply, but I am still really struggling with this. Not sure where that code you provided should go. Where would it fit in relation to my full query/code here…
<?php
$args=array(
'post_type' => 'book',
'post_status' => 'publish',
'posts_per_page' => 12,
'caller_get_posts'=> 1,
'orderby'=> 'date',
'order' => 'DESC'
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo '';
$i = 0;
while ($my_query->have_posts()) : $my_query->the_post();
if($i % 6 == 0) { ?>
<div class="row">
<?php
}
?>
<img src="<?php the_field('cover_image'); ?>" /><br />
<?php the_field('author_name'); ?><br />
<?php the_title(); ?><br />
</div>
<?php
if($i % 6 == 0) { ?>
<?php
}
$i++;
endwhile;
}
wp_reset_query();
?>
Any help appreciated.
Thanks for your replies!
It will be a great feature if you include it in the future.
Meantime, I have managed with a text field, where the client manually types different dates, separated by commas (which later will appear in an array inside a jquery script)
Thanks again,
Victor
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.