Join

Access Listing Links in the WP Block Editor (Gutenberg)

Don't want to mess with code snippets? This is a feature of MyListing Pro.

Instructions

  1. Create a new PHP code snippet.
  2. Copy the contents of code snippet below.
  3. Paste the contents into your code snippet.
  4. Review any notes that I’ve provided.
  5. Save and enable the code snippet.
  6. Test.

Snippet

By default, when using the WP Block Editor (Gutenberg), you can’t reference and link to listings, and this snippet fixes that.

<?php 

add_filter( 'register_post_type_args', function( $args, $post_type ) {
    if ( 'job_listing' === $post_type ) {
        $args['show_in_rest']        = true;
        $args['rest_controller_class'] = 'WP_REST_Posts_Controller';
        $args['exclude_from_search'] = false;
    }
    return $args;
}, 10, 2 );