On your taxonomy archive, you’re not referencing your shows taxonomy in the get_field call for actors. So instead of just:
<?php $get_actors = get_field('actors'); ?>
This needs to be something like:
<?php $get_actors = get_field('actors','shows_'. get_queried_object()->term_id); ?>
You may need to edit the above if shows is your taxonomy slug for the taxonomy you attached the actors ACF field to. You just need a reference in that call to the term you’re pulling this data from and that’s placed in the get_field call as the second argument in the form of term-slug_term-id.
I reworked my template a bit, but still see the same error:
<?php get_header(); ?>
<h1 class="entry-title"><?php single_term_title(); ?></h1>
<div class="archive-meta"><?php if ( '' != the_archive_description() ) { echo esc_html( the_archive_description() ); } ?></div>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<article class="post">
<?php if ( has_post_thumbnail() ) : ?>
<div class="thumb">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
</div>
<?php endif; ?>
<div class="content">
<h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<p class="excerpt-entry"><?php echo strip_tags( get_the_excerpt() ); ?></p>
</div>
</article>
<?php endwhile; endif; ?>
<h2>Actors</h2>
<?php $get_actors = get_field('actors'); ?>
<?php if( $get_actors ): ?>
<ul>
<?php foreach( $get_actors as $actors ): ?>
<li><a href="<?php echo esc_url( get_term_link( $actors ) ); ?>"><?php echo esc_html( $actors->name ); ?></a></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php get_footer(); ?>
When I have nothing linked to the taxonomy, the ACF taxonomy data displays (example: https://a.cl.ly/X6uKqWrL).
In the db query, I see the the following:
SELECT t.term_id
FROM wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt
ON t.term_id = tt.term_id
WHERE tt.taxonomy IN ('actor')
AND t.term_id IN ( 403,404,284 )
ORDER BY t.name ASC
Those term IDs are correct. The full display of DQ queries also looks accurate (example: https://a.cl.ly/WnumRzdq).
I take a single blog post, assign the shows taxonomy for “Broadchurch” for example (example: https://a.cl.ly/6qubm9kN) and save the post. When I refresh the taxonomy archive page, there are no queries at all for ACF, as shown here: https://a.cl.ly/P8u2ZvgJ.
My ACF setup for the field is: https://a.cl.ly/GGu7qZL8 and the location rules are: https://a.cl.ly/8Luq2mdn
I suspect that WP is overriding the ACF query entirely, or somehow preventing it from ever running in this instance where a post has a bunch of terms applied to it, but the term itself also has a term applied to it.
John, thanks for the response. I read through the link you provided and worked it out! In my case, I was able to add the following code, and because I linked it to the key of the field, it only affected that one set of radio buttons. Perfect! Here’s my code:
add_filter(‘acf/fields/taxonomy/wp_list_categories/key=field_69ee9943be86f’, ‘my_acf_fields_taxonomy_query’, 10, 2);
function my_acf_fields_taxonomy_query( $args, $field ) {
// Order by most used.
$args[‘child_of’] = ’14’;
$args[‘orderby’] = ‘title’;
$args[‘order’] = ‘ASC’;
return $args;
}
You can limit the terms shown using one of these two filters
if you are using a select field – acf/fields/taxonomy/query
If you are using a radio or checkbox field – acf/fields/taxonomy/wp_list_categories
actors is a taxonomy, not a post type.
foreach($queried_terms as $query_term):
$query_term is a term in a taxonomy, not a post. You are attempting to set up the term as a post.
setup_postdata($query_term);
I have no idea what this is causing but it is likely a big part of the problem.
If actors is attached to a taxonomy, you need to reference the taxonomy in the get_field call for it. So it might be something like:
get_field('actors','taxonomy_name_X');
Where X is the ID of the taxonomy.
I’m not sure why your filter is not working, it seems like it should be working.
Is it possible that there is another acf/fields/taxonomy/wp_list_categories filter that is interfering?
Try using the field key variant of the filter.
Try increasing the priority of your filter. If this corrects it then might be another active filter on this hook.
What field type are you using? Select, checkbox or radio?
The filter you are trying to use is only available for checkbox and radio fields and will not work for select type fields.
For select type fields you need to use acf/fields/taxonomy/query
I believe that you are talking about having 2 fields where the second taxonomy field shows results based on the selection in another taxonomy field.
This is not easy and I do not have the details. I can only give you a rough outline.
What is the return format of the taxonomy field?
What code are you using to display the link?
The best way to show posts by catetory is to create a custom taxonomy for the posts for the different categories.
It is not possible (or it is extremely difficult and not practical) to show lists of posts based on values saved in a repeater on each post.
I had the same problem, wanted to limit current term in custom taxonomy in wp-admin.
Here is my solution.
// Show 2000 posts pre ajax call, change sort, limit to current taxonomy and term id
add_filter('acf/fields/relationship/query/name=author_sort_list', 'authors_fields_relationship_query', 10, 3);
function authors_fields_relationship_query( $args, $field, $post_id ) {
$url = wp_get_referer();
$parts = parse_url($url);
parse_str($parts['query'], $query);
$term_id = $query['tag_ID'];
$taxonomy = $query['taxonomy'];
if ( isset($taxonomy) && isset($term_id)) {
$args['tax_query'] = array(
array(
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $term_id,
'operator' => 'IN'
)
);
}
$args['posts_per_page'] = 2000;
$args['orderby'] = 'date';
$args['order'] = 'ASC';
return $args;
}
Hello,
For information I just faced this exact situation with ACF PRO 6.0.7 and it’s still not working with Taxonomy field in Repeater field.
Regards
@wpfieldwork Yes!
That fixed things perfectly. I’ve been working through a PHP course and wanted to push myself with a taxonomy query in an ACF block. I could sort of see that the ID was required but couldn’t puzzle it out.
Thank you so much for your time and advice, you’ve made a dev very happy.
@hube2 thanks for your idea but this is all a very “unbeautiful” solution but it would work – i have tested with “tweaking” the relationship a little to add “hide_empty” true and tested it. But now i found a bug and opened a support case:
I found in line includes\libraries\acf\includes\fields\class-acf-field-relationship.php on line 421: $terms = acf_get_grouped_terms( $term_args );
and i followed the function to api-term.php to line 171. In line 181 i changed ‘hide_empty’ to true and give it a try -> it works BUT here seems to be a BUG:
all taxonomies and their corresponding terms are shown (which are not empty). BUT 2 taxonomies (screenshot) are shown because there is in each one “filled term” but not the term itself. I think the problem is the “same” taxonomie name like für posts. but its only the “label” the same not the taxonomy name. It is “dpf_work_category” and “dpf_work_type” – i think there is the bug.
I changed the registered name from one taxonomy from “dpf_work_category” to “dpf_work_category2” and than the missing term is shown under the category name. SO i think its a bug while checking the taxonomy name against the wordpress built-in category names…..
ACF does not have any filters for alter the taxonomy/term list shown in a relatiohship field.
You would have to use a pre_get_terms filter
To apply this filter to only the field being displayed your would use the acf/render_field action and you would have 2 actions, one that happens before acf renders the field to add your filter and one after acf renders the field to remove your filter.
The relationship field shows “if activated” all taxonomies with their corresponding terms objects. But it shows ALL terms. Therefore my question. The first try was to define taxononomies in the PHP section for these fields but i have to define not the taxonomy but taxonomy:term for every allowed selection. This is not very handy. I could generate my own list and push it in the “load_field” section but it would be more useful to have an action or filter to hide the empty TERMS – or if all terms are empty the corresponding taxonomy.
Your question is confusing. A relationship field does not return terms. Are you talking about a taxonomy field?
The problem was solved after examining my code again. I’ve worked with a custom table in the past. Due to difficulties I had retrieved the fields with post_name (‘field_5f4005dc755c5’) and not with the field name (‘deathdate’). I have now re-saved the posts. After saving, I could now retrieve the field values with the field name again, and now the custom fields appear in the taxonomy output! Although I don’t know why it was related to the URL parameter, everything works now. Please excuse the confusion 😉
No, there isn’t any way to include taxonomy terms in a relationship field. You would have to use a taxonomy field.
Its work for me
add_filter('posts_clauses', 'sem_order_by_stock_status');
function sem_order_by_stock_status($posts_clauses) {
global $wpdb;
// only change query on WooCommerce loops when ACF fields are not requested in the WHERE statement
if (!is_acf_request($posts_clauses['where']) && is_woocommerce() && (is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy())) {
$posts_clauses['join'] .= " INNER JOIN $wpdb->postmeta istockstatus ON ($wpdb->posts.ID = istockstatus.post_id) ";
$posts_clauses['orderby'] = " istockstatus.meta_value ASC, " . $posts_clauses['orderby'];
$posts_clauses['where'] = " AND istockstatus.meta_key = '_stock_status' AND istockstatus.meta_value <> '' " . $posts_clauses['where'];
}
return $posts_clauses;
}
function is_acf_request($text){
if (strpos($text, 'acf-field'))
return true;
return false;
}
Hi John, it was the posts that weren’t being ordered correctly. But this post managed to help my resolve the issue https://stackoverflow.com/questions/50930583/displaying-custom-post-types-taxonomy
Thanks!
Your filter on the hook posts_clauses affects every query that is done, in this case it will happen on any page load where this is true
if ( is_woocommerce() && ( is_shop() || is_product_category() || is_product_tag() || is_product_taxonomy() ) ) {
and this will effect ACF queries to get values of fields.
I cannot tell you how to correct this, when I’m altering a WP query I generally do this by using a pre_get_posts action and for example if I want to change the orderby value I do it by altering the main query, not by adding clauses to the query.
A taxonomy field returns an array of terms if your field settings allow selecting more than one term. In this case you have to loop over that array
$terms = get_field('cast_category');
if( $terms ) {
foreach ($terms as $term) {
?><h2><?php echo esc_html( $term->name ); ?></h2><?php
}
}
https://www.advancedcustomfields.com/resources/taxonomy/
This is my main plugin class:
<?php
/**
* The file that defines the core plugin class
*
* A class definition that includes attributes and functions used across both the
* public-facing side of the site and the admin area.
*
* @link https://example.com
* @since 1.0.0
*
* @package Plugin_Name
* @subpackage Plugin_Name/includes
*/
/**
* The core plugin class.
*
* This is used to define internationalization, admin-specific hooks, and
* public-facing site hooks.
*
* Also maintains the unique identifier of this plugin as well as the current
* version of the plugin.
*
* @since 1.0.0
* @package Plugin_Name
* @subpackage Plugin_Name/includes
* @author Your Name <[email protected]>
*/
class Picture_Frame {
/**
* Store plugin main class to allow public access.
*
* @since 1.0.0
* @var object The main class.
*/
public $main;
/**
* Store plugin admin class to allow public access.
*
* @since 20180622
* @var object The admin class.
*/
public $admin;
/**
* Store plugin public class to allow public access.
*
* @since 20180622
* @var object The admin class.
*/
public $shared;
/**
* Store plugin public class to allow public access.
*
* @since 20180622
* @var object The admin class.
*/
public $public;
/**
* The loader that's responsible for maintaining and registering all hooks that power
* the plugin.
*
* @since 1.0.0
* @access protected
* @var Plugin_Name_Loader $loader Maintains and registers all hooks for the plugin.
*/
protected $loader;
/**
* The unique identifier of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_name The string used to uniquely identify this plugin.
*/
protected $plugin_name;
/**
* The unique prefix of this plugin.
*
* @since 1.0.0
* @access protected
* @var string $plugin_prefix The string used to uniquely prefix technical functions of this plugin.
*/
protected $plugin_prefix;
/**
* The current version of the plugin.
*
* @since 1.0.0
* @access protected
* @var string $version The current version of the plugin.
*/
protected $version;
/**
* Define the core functionality of the plugin.
*
* Set the plugin name and the plugin version that can be used throughout the plugin.
* Load the dependencies, define the locale, and set the hooks for the admin area and
* the public-facing side of the site.
*
* @since 1.0.0
*/
public function __construct() {
if ( defined( 'PICTURE_FRAME_VERSION' ) ) {
$this->version = PICTURE_FRAME_VERSION;
} else {
$this->version = '1.0.0';
}
$this->main = $this;
$this->plugin_name = 'picture-frame';
$this->plugin_prefix = 'pfx_';
$this->load_dependencies();
$this->set_locale();
$this->define_admin_hooks();
$this->define_public_hooks();
}
/**
* Load the required dependencies for this plugin.
*
* Include the following files that make up the plugin:
*
* - Plugin_Name_Loader. Orchestrates the hooks of the plugin.
* - Plugin_Name_i18n. Defines internationalization functionality.
* - Plugin_Name_Admin. Defines all hooks for the admin area.
* - Plugin_Name_Public. Defines all hooks for the public side of the site.
*
* Create an instance of the loader which will be used to register the hooks
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies() {
/**
* The class responsible for defining all actions that
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-acf.php';
/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-loader.php';
/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-i18n.php';
/**
* The class responsible for defining all actions that
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-cpt.php';
/**
* The class for generating dropdowns in custom post types admin
*/
//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/libraries/walker.php';
/**
* Template Loader
*/
//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-template-loader.php';
/**
* The class responsible for defining all actions that occur in the admin area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-picture-frame-admin.php';
/**
* The class responsible for defining all actions that occur in the public-facing
* side of the site.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-picture-frame-public.php';
/**
* The class responsible for defining all actions that occur in admin and public area.
*/
require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-shared.php';
/**
* The class responsible for generating the help sections.
*/
//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/libraries/class-contextual-help.php';
/**
* The class responsible for defining all help sections that occur in admin area.
*/
//require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-picture-frame-help.php';
$this->loader = new Picture_Frame_Loader();
}
/**
* Define the locale for this plugin for internationalization.
*
* Uses the Plugin_Name_i18n class in order to set the domain and to register the hook
* with WordPress.
*
* @since 1.0.0
* @access private
*/
private function set_locale() {
$plugin_i18n = new Picture_Frame_I18n();
$this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' );
}
/**
* Register all of the hooks related to the admin area functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
$this->admin = new Picture_Frame_Admin( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
$this->cpt = new Picture_Frame_CPT( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
//$this->acf = new Picture_Frame_ACF( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
$this->shared = new Picture_Frame_Shared( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
//$this->help = new Picture_Frame_Help( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
//$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_styles' );
//$this->loader->add_action( 'admin_enqueue_scripts', $this->admin, 'enqueue_scripts' );
$this->loader->add_action( 'admin_menu', $this->admin, 'pf_create_menu' );
// add custom post types and taxonomies
$this->loader->add_action( 'init', $this->cpt, 'pf_create_cpt' );
// create fake submenu to add other taxonomies
$this->loader->add_action( 'admin_menu', $this->cpt, 'pf_create_submenus' );
// highlight correct menu for taxonomies
//$this->loader->add_action( 'parent_file', $this->cpt, 'pf_highlight_menu' );
//$this->loader->add_action( 'submenu_file', $this->cpt, 'pf_highlight_submenu' );
// add columns to cpt exhibition
//$this->loader->add_filter( 'manage_pf_exhibition_posts_columns', $this->cpt, 'pf_add_columns_to_exhibition' );
// fill columns in cpt exhibition
//$this->loader->add_action( 'manage_pf_exhibition_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_exhibition', 10, 2 );
// add columns to cpt work
//$this->loader->add_filter( 'manage_pf_work_posts_columns', $this->cpt, 'pf_add_columns_to_work' );
// fill columns in cpt work
//$this->loader->add_action( 'manage_pf_work_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_work', 10, 2 );
// add columns to taxonomy artist
//$this->loader->add_filter( 'manage_edit-pf_work_artist_columns', $this->cpt, 'pf_add_columns_to_taxonomy_artist' );
// fill columns in artist taxonomy
//$this->loader->add_filter( 'manage_pf_work_artist_custom_column', $this->cpt, 'pf_add_columns_content_to_taxonomy_artist', 10, 3 );
// add columns to taxonomy artist
//$this->loader->add_filter( 'manage_edit-pf_work_client_columns', $this->cpt, 'pf_add_columns_to_taxonomy_client' );
// fill columns in artist taxonomy
//$this->loader->add_filter( 'manage_pf_work_client_custom_column', $this->cpt, 'pf_add_columns_content_to_taxonomy_client', 10, 3 );
// add columns to cpt zone
//$this->loader->add_filter( 'manage_pf_zone_posts_columns', $this->cpt, 'pf_add_columns_to_zone' );
// fill columns in cpt screen
//$this->loader->add_action( 'manage_pf_zone_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_zone', 10, 2 );
// add columns to cpt screen
//$this->loader->add_filter( 'manage_pf_display_posts_columns', $this->cpt, 'pf_add_columns_to_display' );
// fill columns in cpt screen
//$this->loader->add_action( 'manage_pf_display_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_display', 10, 2 );
// add columns to cpt view
//$this->loader->add_filter( 'manage_pf_view_posts_columns', $this->cpt, 'pf_add_columns_to_view' );
// fill columns in cpt screen
//$this->loader->add_action( 'manage_pf_view_posts_custom_column', $this->cpt, 'pf_add_columns_content_to_view', 10, 2 );
// register sortable columns / dropdowns for post type
//$this->loader->add_action( 'restrict_manage_posts', $this->cpt, 'pf_filter_post_type_by_taxonomy' );
// hide taxonomies from quick edit
//$this->loader->add_action( 'quick_edit_show_taxonomy', $this->cpt, 'pf_hide_taxonomies_quick_edit', 10, 3 );
// add custom image sizes
//$this->loader->add_action( 'after_setup_theme', $this->admin, 'pf_add_image_sizes' );
// add styles to admin head for custom post types
//$this->loader->add_action( 'admin_head', $this->admin, 'pf_add_styles_to_admin_head' );
// delete attachement
//$this->loader->add_action( 'deleted_post', $this->admin, 'pf_delete_transients' );
// add custom post type works to doashboard
//$this->loader->add_action( 'dashboard_glance_items', $this->cpt, 'pf_add_glance_content' );
// add help screens for all plugin pages
//$this->loader->add_action( 'init', $this->help, 'pf_add_help' );
}
/**
* Register all of the hooks related to the public-facing functionality
* of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_public_hooks() {
$this->public = new Picture_Frame_Public( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
$this->shared = new Picture_Frame_Shared( $this->get_plugin_name(), $this->get_plugin_prefix(), $this->get_version(), $this->main );
$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'enqueue_scripts' );
$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'pf_enqueue_styles' );
$this->loader->add_action( 'wp_enqueue_scripts', $this->public, 'pf_enqueue_scripts' );
// Shortcode name must be the same as in shortcode_atts() third parameter.
//$this->loader->add_shortcode( $this->get_plugin_prefix() . 'shortcode', $this->public, 'pfx_shortcode_func' );
// loads the custom template file for custom post type single public view
$this->loader->add_filter( 'single_template', $this->public, 'pf_get_template' );
}
/**
* Run the loader to execute all of the hooks with WordPress.
*
* @since 1.0.0
*/
public function run() {
$this->loader->run();
}
/**
* The name of the plugin used to uniquely identify it within the context of
* WordPress and to define internationalization functionality.
*
* @since 1.0.0
* @return string The name of the plugin.
*/
public function get_plugin_name() {
return $this->plugin_name;
}
/**
* The unique prefix of the plugin used to uniquely prefix technical functions.
*
* @since 1.0.0
* @return string The prefix of the plugin.
*/
public function get_plugin_prefix() {
return $this->plugin_prefix;
}
/**
* The reference to the class that orchestrates the hooks with the plugin.
*
* @since 1.0.0
* @return Plugin_Name_Loader Orchestrates the hooks of the plugin.
*/
public function get_loader() {
return $this->loader;
}
/**
* Retrieve the version number of the plugin.
*
* @since 1.0.0
* @return string The version number of the plugin.
*/
public function get_version() {
return $this->version;
}
}
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.