
Hi @brunocloutier,
You can make use of the acf/fields/post)object/query filter to change the order of the posts queried by the WP_Query function and thus change the posts displayed by the field.
I would recommend you modify the $args array and change the ‘order_by’ value to ‘ID’ or ‘author’
The code should look like this:
<?php
function my_post_object_query( $args, $field, $post )
{
// modify the order
$args['orderby'] = 'ID';
return $args;
}
// filter for every field
add_filter('acf/fields/post_object/query', 'my_post_object_query', 10, 3);

Hi @lletnek,
Thank you for the submission of the feature request, this would really make a nice addition to the plugin.
I have sent this information to the developer for consideration and hopefully this will see its way into the plugin in the near future.

Hi @oppodeldoc
The get_field_objects() function would not work in this scenario since you are trying to query some term objects.
I would recommend you make use of a for each loop to get the terms as shown below:
<?php
$terms = get_field('taxonomy_field_name');
if( $terms ): ?>
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>

Hi @jursdotme
Thank you for the great description of the issue, the feature request has been received and has been sent forth to the developer 🙂
This would really make a great addition to the plugin!

Hi @sascha
Thank you for the feature request. Information about this has been forwarded to the developer and hopefully this will see its way in to the plugin in the near feature.

Hi @pilgrimish
It looks like the last query in your code is the one which is related to your question, is this correct?
Within this ‘client’ loop, you will need to use the get_posts function to see if any posts exist (‘work’) which contain a custom field value where the current ‘client’ has been selected.
Is all the rest of your code working?
If so, the additional get_posts should be quite straight forward. Please read over the doc to understand how you can use compare LIKE to find a value within a serialized array.
Thanks
E

Hi @keliix06
Thanks for the bug report.
It may be possible that due to the button having a title attribute, the button may need to be clicked twice, can you please remove your extra code and try this first?
There should be a solution for this that does not require an extra touchstart action for every field JS.
Thanks
E

$query->set('posts_per_page', -1); should be correct.
Sorting by 2 meta field, until quite recently was not really possible, or at best difficult. However, WP 4.2 introduced and improvement that will allow this. See this: https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

You can call acf_get_fields() using the field_group key, for example: $fields = get_fields('group_5570c274a5741');
This will return a multidimensional array. You could then look through the array to find all fields of a specific type.
I doubt this would cause any performance issues. This information is cached by ACF so that they will not be re-queried.

The question is not really an ACF question but a WP/TniyMCE question.
Here is a good article: https://vip.wordpress.com/documentation/register-additional-html-attributes-for-tinymce-and-wp-kses/
you can find more info by doing a google search for “altering allowed html elements in wp tinymce”

Not sure if you still need help with this, trying to clear up some older questions.
If I understand correctly, on you site the “post” post type has a custom field on it that is named “drivers” and this field is a relationship field.
If this is true then what you have should work. The only thing I can come up with looking at your code is that you’re either querying the wrong post type or that the field name is not “drivers”

I’m only guessing, but the reason this is not a feature is because different people would want to see different things, and the list of what could be shown is quite large: order, group key, location rules, what’s hidden on the screen, position, style. Each person may want different things depending on their own preferences and needs.
Add this to functions.php and it will add the order value to the list.
function acf_field_group_columns($columns) {
$columns['menu_order'] = __('Order');
return $columns;
} // end function reference_columns
add_filter('manage_edit-acf-field-group_columns', 'acf_field_group_columns', 20);
function acf_field_group_columns_content($column, $post_id) {
switch ($column) {
case 'menu_order':
global $post;
echo '<strong>',$post->menu_order,'</strong>';
break;
default:
break;
} // end switch
} // end function reference_columns_content
add_action('manage_acf-field-group_posts_custom_column', 'acf_field_group_columns_content', 20, 2);

heh, yes, I had originally thought of making this some type of plugin, but the thought of maintaining it turned me off. It is mostly a plugin but not anything that is fit for public consumption.
First so you know what you’re looking at, I don’t use jQuery, the script that does the replacement is actually quite small and efficient.
A little background about the ACF fields. In my ACF field group I have a radio button. The user can select to upload a single image and use WP auto resized images or they can choose to upload a different image for each size. The image widths that are used are 320, 640, 768, 1024 and 1280. The image fields displayed for upload are all conditional fields depending on what is selected. All of the sizes have WP image sizes created for them like.
add_image_size('image-size-name', $width, 9999);
In the PHP I get the fields, based on what the user has selected, get the right image urls and generate an tag that is used by picturefill.js
I put a copy of it on this repo, it is the only thing currently there
https://github.com/Hube2/blunt-panes
If you have any questions about the JS I’d be glad to answer them over on the issue section for that repo so we don’t fill up this thread with something that is really not related to ACF.

New code mixed into yours and commented
<?php
$images = get_field('photo_gallery','17');
if( $images ):
shuffle($images); // randomizes the image array
$max = 10; // set the max here;
$count = 0; // current count
?>
<ul>
<?php
foreach( $images as $image ):
$count++; // increment count
// if count is greater than limt, stop showing images
if ($count > $max) {
break;
}
?>
<li>
<a href="<?php echo $image['url']; ?>" rel="lightbox">
<img src="<?php echo $image['sizes']['photo-gallery']; ?>" alt="<?php echo $image['alt']; ?>" />
</a>
</li>
<?php endforeach; ?>
<div id="clearfloat"></div>
</ul>
<?php endif; ?>

In most cases it would be much easier to alter the code in your template to check for a value an if it does not exist then show the default.
$value = get_field('my_field');
if ($value === false) {
$value = 'default_value';
}
To do it the other way, you can:
I generally do the former and code my templates to deal with default values because I assume that any field might be empty.

Hi @timo
For the tax_query, change your code to the following:
function my_relationship_query( $args, $field, $post )
{
// increase the posts per page
$args['posts_per_page'] = 10;
$args['tax_query'] = array(
array(
'terms' => '30'
)
);
return $args;
}
Check out this link for more information: https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
For accessing the term object id dynamically, you could consider using get_queried_object() function. Here is the link to the documentation: https://codex.wordpress.org/Function_Reference/get_queried_object

First question I have is, what will you use to put responsive background images into the backgrounds. I’m curious because I was recently looking for some way to do this and didn’t find anything. I had to settle for using https://github.com/scottjehl/picturefill which requires an tag so I had to insert the images into the content.
The way I did this was that I provided the client with the ability to upload alternate images cropped at different sizes and I built the tags dynamically.

Trying to clear up some old topics. This question appears to be about an add on for ACF that was created by someone else and is no longer supported.
This can be easily accomplished by created several text fields, and or select fields if you wanted to get fancy with state/country fields instead of having a single field to hold everything.

I know this is an old question and the OP may not still be looking for help, but someone may have the same question.
Using the above code to work from:
global $post;
$posts = get_field('doctors');
if ($posts) {
foreach ($posts as $post) {
setup_postdata($post);
$name = get_field('doctor_name');
if ($name) {
$field_object = get_field_object('doctor_name');
echo $field_object[label],': ',$name;
}
} // end foreach
wp_reset_postdata();
} // end if posts

Not a problem, I’m just trying to help out with clearing up questions here on the support forums and it was something I could answer.

I know that this is an old question and you may not need help with it at this point, but someone else may be looking for similar information.
What you want to accomplish is possible to do before you get to the content. In your header.php files you can do something like:
$queried_object = get_queried_object();
if (isset($queried_object->ID)) {
$post_id = $queried_object->ID;
$field_value = get_field('my_field', $post_id);
}
Thank you for your help. I ended up just using a true/false custom field with an if/else statement. Being it was only on one custom post type I just added the php in post type.
<?php if( get_field('image4') ) { echo "Photo's taken by: <a href='http://www.sample.com/'><img src='http://photolinkhere.jpg' /></a>"; } else{} ?>

After some more thought, you could add custom fields to the image attachment itself.
Location: Attachment : is equal to : all
and then you can use the attachment id to get the data for the specific image. More information is here: http://www.advancedcustomfields.com/resources/how-to-get-values-from-a-media-attachment/ specifically the section on “Retrieve from another image custom field”

Question one:
That’s the easiest and fastest way to do it using fields. On the other hand, you could create a custom taxonomy that is hierarchical and then at the top level create the states and then on the second level you could have counties.
To do it with fields so that only the counties you want are loaded would take a lot more work, you’d need to create some custom javascript to reload the county select field whenever the state field was changed. Possible, but takes longer and the result from the users perspective will be the same.
Question 2:
I would also carefully name my county fields. If you are using the state abbr for the value of state then:
ia_county, nm_county, etc
then you can simplify getting the county
$county_field = $state.'_county';
$county = get_field($county_field)
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.