• Resolved Adrian

    (@adrian2k7)


    Hi,

    I’m not sure if this is a problem, or I’m doing something wrong.

    • We have a custom taxonomy: my_category
    • Added a field using ACF: my_field
    • Added the Meta Field Block to the single taxonomy template using the new Website Editor

    → The block seems to “ignore” the context for the single term page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Phi Phan

    (@mr2p)

    Hi @adrian2k7, This block does not support term meta field by default, but you can add custom code to make it work with it or any kind of meta fields. Please refer to the plugin description for more details. Here is the sample code I copy from the plugin description:

    // Create a function to build the value for the field.
    function yourprefix_get_attr_value( $term_id ) {
      $cat_attr_value = get_term_meta( $term_id, 'cat_attr', true );
    
      // If the meta field is an ACF Field. The code will be:
      // $cat_attr_value = get_field( 'cat_attr', 'term_' . $term_id );
    
      return $cat_attr_value;
    }
    
    // Render the block on the front end.
    add_filter( 'meta_field_block_get_block_content', function ( $block_content, $attributes, $block, $post_id ) {
      $field_name = $attributes['fieldName'] ?? '';
    
      // Replace unique_name_for_cat_attr with your unique name.
      if ( 'unique_name_for_cat_attr' === $field_name && is_tax( 'product_cat' ) ) {
        $term_id = get_queried_object_id();
        $block_content = yourprefix_get_attr_value( $term_id );
      }
    
      return $block_content;
    }, 10, 4);
    Thread Starter Adrian

    (@adrian2k7)

    Hello Phi,

    Thank you.

    Then this is a feature request, would be much easier to not write custom code ??

    Adrian

    Plugin Author Phi Phan

    (@mr2p)

    Thank you @adrian2k7 for your suggestion. It has been on my todo list for a future version.

    Regards,

    Phi

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Not working on custom taxonomy page (ACF)’ is closed to new replies.