Advanced Custom Fields: Sorting custom columns with custom fields sorts only by date

It appeared it was due to the fact that WordPress doesn’t understand that you need to order by certain post meta unless you specify it. So in my case adding this fixed the sorting issue: add_action( ‘pre_get_posts’, ‘custom_orderby’ ); function custom_orderby( $query ) { if( ! is_admin() ) return; $orderby = $query->get( ‘orderby’); if( ‘featured’ … Read more

Changing a specific value inside a complex repeater/flexible content field (ACF)

Answering my own question again. 😛 I finally found this Gist that lets me get and set array variables via dot notation: https://gist.github.com/elfet/4713488 So I included the DotNotation class and now my code looks like this (skipping all sorts of error checking here) : $fieldmap_string = ‘key1.key2.key3.etc’; $current_page_content = get_field(‘page_content’, $source_post_id); $parsed_current_content = new DotNotation($current_page_content); … Read more

Retrieve tags data in post body

There are two ways to approach this: modify the existing the_tags function or build your own. the_tags ultimately relies on get_the_term_list, which returns a list of hyperlinked tags. You would have to use regular expressions to add classes and styles to that using a filter. That would be quite cumbersome. So, my preferred approach would … Read more

My get_terms not working for custom fields

The issue is with ACF as discussed here along with a solution: https://support.advancedcustomfields.com/forums/topic/how-to-use-wp-term-meta-on-acf-the-easy-way/ Courtesy of various posters there, the code I added to mu-plugins is: function acf_update_term_meta($value, $post_id, $field) { $object = get_queried_object(); $term_id = intval(filter_var($post_id, FILTER_SANITIZE_NUMBER_INT)); if (!isset($object->taxonomy) || !isset($object->term_id) || $term_id != $object->term_id) { // the current object is not a term return … Read more

Using Pagination with Timber Routes

After some messing around (and actually looking at the docs properly!) I have solved the problem. In my routing, I just need to add another map to handle paging with my custom routing: Routes::map(‘items/browse/:field/:value’, function($params) { $query = array( ‘post_type’ => ‘item’, ‘meta_key’ => $params[‘field’], ‘meta_value’ => $params[‘value’] ); Routes::load(‘archive-item.php’, $params, $query); }); Routes::map(‘items/browse/:field/:value/page/:page’, function($params) … Read more