Yeah, generally whenever you have multiple “posts” being listed you are using a loop (literally “looping through” them). While this is not a WordPress-specific concept, you can read about it (in the context of WP) here: http://codex.wordpress.org/The_Loop
ACF actually does have this feature (though I didn’t realize it until your question raised my curiosity).
You can filter relationship query results using the filters ‘acf/fields/relationship/query’, ‘acf/fields/relationship/query/name={{field_name}}’, and ‘acf/fields/relationship/query/key={{field_key}}’ in increasing specificity. So to get only published posts, you would have something like:
add_filter('acf/fields/relationship/query/name=your_relationship_name', 'relationship_options_filter', 10, 3);
function relationship_options_filter($options, $field, $the_post) {
$options['post_status'] = array('publish');
return $options;
}
You also might have to add ‘type’ => ‘numeric’ depending on the values. See: http://codex.wordpress.org/wp_query#Custom_Field_Parameters
So you want to count posts that have a field named ‘aangeboden_door’ with several different values? I think you’ll have to modify the function so as to add meta_value as an array (of values) and setting ‘compare’ => ‘IN’. Try something like this:
// ...
if ( $meta_key && $meta_value ) {
if ( is_array($meta_value) ) {
$args['meta_query'][] = array('key' => $meta_key, 'value' => $meta_value, 'compare' => 'IN');
}
else {
$args['meta_query'][] = array('key' => $meta_key, 'value' => $meta_value);
}
}
// ...
I would start out by modifying a copy of the “Tab” field – adding an option for the number of columns, modifying the field JS to look for “column” fields and apply classes, adding CSS to admin_head, etc.
I like the idea of a git repo rather than gists so as to give it some structure. Also, a repo would allow there to be multiple contributors, issue tracking, etc. There could be folders for each “package” (directory) along with .md files for instructions. And if Elliot wanted to tie this into the forum, I’m sure the Github API could help accomplish that.
Update: Just created a test repo, invited @mrwweb and @elliot (on GitHub) to test collaboration. If this works out, I can transfer ownership.
Is ‘contact_info’ a field for Category terms or Brand terms? Based on the field that works, I’m guessing the latter, in which case you’ll need to change the 2nd get_field argument:
$custom_field = get_field('contact_info', 'product_brand_' . $term->term_id);
The first issue is not ACF related (its throwing an error before getting to the ACF function). If your taxonomy slug is ‘product_brand’, your get_the_terms() function should be
$terms = get_the_terms($post->ID, "product_brand");
In addition to checking if the term array is empty, you should check for a WP error like:
if ( $terms && ! $terms->is_wp_error() ) { ... }
Since WP_Error is an object, it can’t be used as an array like in $term[0].
The second code posted should work on a fresh install, provided you have a field called “field_name” (with a value) for taxonomy “Category” for the term with ID 7.
Should code block 2 be
$value = get_field('color_scheme_color');
rather than
$value = get_field('color_scheme_name');
? Just looking at your field setup in block 3, it looks like you’re setting the field choices to ‘color_scheme_color’ = ‘color_scheme_name’.
I’ve also been looking for a way to get the key from a name. The best solution I’ve come up with is adding a function which does a switch/case on the field name and applies a filter to return the key. However, it does require that you manually code a case/return/break for each field (probably not practical if you’ve got more than a few dozen fields).
Code here: https://gist.github.com/wells5609/5971010
You have found the biggest weakness of WordPress. Unfortunately, it doesn’t have a simple solution (hence why there are so few search plugins, let alone good ones).
That said, you can look into Relevanssi (http://wordpress.org/plugins/relevanssi/), which is one of the better ones I’ve come across. It does allow you to search by field, but also installs some extra tables and adds a bit of server overhead.
If you’re running Apache, your best bet for a full-featured search is probably to install Solr and then integrate with WP (I remember seeing a plugin to help with this).
Good luck
Change the “orderby” arg to ‘orderby’ => ‘meta_value’ and then specify ‘meta_key’ => ‘presenter’ (rather than ‘meta_value’ => ‘presenter’). This will order the query results by the meta_value of ‘presenter’.
It sounds like you’re trying to also query posts with a specific ‘presenter’ value. If so, add to the $args array:
'meta_query' => array(
array(
'key' => 'presenter',
'value' => '"' . $presenter_value . '"',
'compare' => 'LIKE',
)
)
You’ll need to set the second function parameter to ‘category-slug_2’ where ‘2’ is the term ID. So for example:
the_field('test_field', 'beer_' . $term_id);
would output the “test_field” value for the term with ID $term_id in the “beer” taxonomy.
ACF has a number of hooks for modifying fields – you’ll probably want to look at ‘acf/load_field’: http://www.advancedcustomfields.com/resources/filters/acfload_field/
@AmandaB – Wow, that looks great. Nicely done. Seems there would be interest in an add-on that does something similar…
I’ve also been looking into ways to condense fields in the post edit screens, particularly number fields (which rarely need the full width). One idea is a “columns” field which, like the tab field, finds the fields proceeding it and wraps them in a specified number of columns (field option).
What action is your AJAX request calling? I’m guessing you’ll just need to pass the ‘minvalue’, ‘maxvalue’, and post ID (i.e. via $_POST) to some custom handler function, for example:
function handle_slider_min_max() {
$post_id = $_POST['post_id'];
$min = $_POST['minvalue'];
$max = $_POST['maxvalue'];
update_field('slider_field_min', $min, $post_id);
update_field('slider_field_max', $max, $post_id);
}
// user logged in
add_action('wp_ajax_handle_slider_min_max', 'handle_slider_min_max');
// user not logged in
add_action('wp_ajax_nopriv_handle_slider_min_max', 'go_away');
Note: you should use the field key in update_field(), rather than specifying it by name.
Also, ‘go_away’ is not a native WP function (although it should be).
In addition to Elliot’s suggested method, if you didn’t want to change the value saved to the database, you could use the DateTime ‘format’ method:
$date = get_field("my_date_field");
// assuming your return format is "Ymd"
$dateTime = DateTime::createFromFormat("Ymd", $date);
if ( is_object($dateTime) ) {
$month = $dateTime->format('F');
$year = $dateTime->format('Y');
//...
}
Try replacing ‘category_’ with your custom taxonomy slug
ACF does have a method to load fields from code using “Export as PHP”. However, this does require that the fields are first created using the GUI, then exported, deleted via GUI, and included via PHP file… got me thinking about an “ACF field generator” which would basically be a web-based version of the GUI that outputs PHP code (like generatewp.com but for ACF). Of course, then there’s always the issue of name conflicts, incompatibility with custom field types, etc…
This sounds like more of an HTML issue than something to do with ACF.
If links are opening in a new window, you probably have target=”_blank” on the anchor element, right? To get an overlay would depend on your HTML/CSS/JS setup. For example, if you’re using Twitter Bootstrap, this would be done by setting data-toggle=”modal” and data-target equal to the modal div selector (which would have the video as its content).
Try this:
$lang = get_field('language');
if ( 'en' === $lang ) {
echo "ENGLISH Flag icon";
}
elseif ( 'fr' === $lang ) {
echo "FRENCH Flag icon";
}
Try this function: https://gist.github.com/wells5609/5944561
It counts posts of a given post type with either a meta_key, meta_value, or key/value pair. Results are cached for 3 hours (you can change this depending on how often the post count will change). Use in a template like:
$post_count = get_post_count_by_meta('some_key', 'some_value', 'some-post-type');
echo $post_count;
I’m liking the typeahead on users and tags.
Another possible feature – the ability to view only unread/unsolved (question) topics?
Are you using the ACF front-end form functions or building a custom form?
If the former, see http://www.advancedcustomfields.com/resources/tutorials/creating-a-front-end-form/. In the acf_form() options array, you’ll just specify ‘field_groups’ as an array of ACF post object ID’s.
What plugin(s) did you use to import the CSV data?
Also, what do you see when you var_dump() the field object?
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.