Support » Developing with WordPress » Block-Editor: Problem with internal text links to custom taxonomies

  • Hello to the community,

    I use WP 5.2 with the Gutenberg Editor to create a recipe page. I have created a CPT (recipe) and a Custom Taxonomy (recipe_tax). Everything works fine.

    In the default posts or pages of WP, I tried to set text links to my custom taxonomies that don’t work. At the moment I can only link to articles and pages there.

    After some research I found the following “wp_link_query” function on Github (see also: https://gist.github.com/emzo/6f86f50199c09d2f4ce6863401a307fb).

    <?php
    add_filter( 'wp_link_query', 'pm_wp_link_query_term_linking', 99, 2 );
    function pm_wp_link_query_term_linking( $results, $query ) {
      // Query taxonomy terms.
    	$taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'names' );
    	$terms = get_terms( $taxonomies, array(
    		'name__like' => $query['s'],
    		'number'     => 20,
        'hide_empty' => false,
    	) );
    	// Check if any taxonomies were found.
    	if ( ! empty( $terms ) ) {
    		foreach ( $terms as $term ) {
          $results[] = array(
            'ID' => 'term-' . $term->term_id,
            'title' => html_entity_decode( $term->name, ENT_QUOTES, get_bloginfo( 'charset' ) ),
            'permalink' => get_term_link( intval( $term->term_id ), $term->taxonomy ),
            'info' => get_taxonomy( $term->taxonomy )->labels->singular_name,
          );
    		}
    	}
      return $results;
    }

    I added this code to my functions.php to extend the internal linking to my custom taxonomies.

    In the Classic Editor this works smoothly, in the new Block Editor unfortunately not.

    Here are two screenshots to illustrate the problem:

    1. Block Editor (Gutenberg)
    https://drive.google.com/open?id=1xWwisY_SbJSkDewhcis9TVB0RlUVGX21

    2. Classic Editor:
    https://drive.google.com/open?id=1dAnA2im1k8zPXHO6e2jyh5J0hBfWt5uV

    I’d appreciate your help.

  • You must be logged in to reply to this topic.