Home › Forums › Front-end Issues › Filter shortcode taxonomy list
I’m trying to filter the taxonomy
list in the image (knipsel) to only make it show the tag that is equal to the current posts_id
. For example: if the post_id
of a post is 10586
then in the list it should only show the tag 10586
.
Project_tag
is an ACF taxonomy field which is placed in the form suggested-items
. I placed the shortcode of the form in a shortcode element (from elementor) to get the list of tags in the image (knipsel). shortcode name is suggested-items
In functions.php I tried the following code to filter the output of the shortcode:
function loop_the_tags() {
$taxonomy = 'project_tag';
// Get the term IDs assigned to post.
$post_tags = get_the_tags( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
// Separator between links.
$separator = ', ';
if ( ! empty( $post_tags ) && ! is_wp_error( $post_tags ) ) {
$tag_ids = implode( ',' , $post_terms );
$tags = wp_list_categories( array(
'title_li' => '',
'style' => 'none',
'echo' => false,
'taxonomy' => $taxonomy,
'include' => $tag_ids
) );
$tags = rtrim( trim( str_replace( '<br />', $separator, $tags ) ), $separator );
// Display post categories.
echo $tags;
}
}
In this case it should only return the checkbox with number 10586. (ouput-frontend image)
*Update
I managed to show only the checkbox with a value matching the ID of the current post with the following code:
function my_acf_load_field( $field )
{
global $post;
$post_id = get_the_ID();
$field['choices'] = array();
wp_reset_query();
$query = new WP_Query(array(
'post_type' => 'projectsoverview',
'orderby' => 'menu_order',
'order' => 'ASC',
'posts_per_page' => -1,
'tag' => $post_id
));
foreach($query->posts as $product_id=>$macthed_product){
$choices[$macthed_product->ID] = $macthed_product->post_title;
}
$field['choices'] = array();
if( is_array($choices) )
{
foreach( $choices as $key=>$choice )
{
$field['choices'][$key] = $choice;
}
}
wp_reset_query();
return $field;
}
Now I am trying to modify the query to only return the checkboxes that are checked. Is there a parameter that I can use for that purpose? Or is there another way?
You must be logged in to reply to this topic.
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.