2

How can i filter the link given in "link to existing content".

Eg:enter image description here

As in the above image. I just want WSP BANNER TO BE SHOWN.

where WSP BANNER & CALENDAR are custom POST types

Any help will be appreciable.

1
  • So you want to filter the list? Commented Jun 21, 2012 at 6:53

4 Answers 4

2

Currently there are no ready filters available for this purpose. A ticket has been posted for the request.Lets hope we get one soon.

Instead of hardcoding your custom post types its better to create a filter hook and use it

Till then you can create your own filter.

Open includes/class-wp-editor.php and make folowing changes at line no 712

$pt_names = apply_filters('custom_insert_link_suggestion_filter',array_keys( $pts ));

we just added a new filter instead of getting all the public post types

Then in your theme add following code to filter the internal link custom post type

function my_filter_function($allowed_post_types)
{


if( condition chek)
{
         return array('page','your custom post types');
}


}
add_filter('custom_insert_link_suggestion_filter','my_filter_function',10,1);
1

if it's very very urgent, you may be want to edit class-wp-editor line 711 to

$pts = get_post_types( array( 'name' => 'your_post_type','public' => true ), 'objects' );

, otherwise leave AS IS

4
  • 1
    I would highly suggest not to edit the core files, unless it can save your job ;) Commented Jun 21, 2012 at 7:17
  • as I said, if very very urgent :D
    – Dazilio
    Commented Jun 21, 2012 at 7:21
  • Yep correct! :D Commented Jun 21, 2012 at 7:26
  • Thanks for your answer and comments. Ya its clients requirement.
    – Sujeet
    Commented Jun 21, 2012 at 9:03
0

Check the file class-wp-editor.php, line no. 742 onwards. The list doesn't have any filters applied to it. So I guess you can't change it!

More, in the same file, line no. 689, the function wp_link_query is called via an AJAX request for getting this list, it too doesn't have any filters to change the post types!

Hence, you have to live with it! ;)

0

I wrote a plugin for that. You can download it here from the plugin repository.

Install it and then put this filter in your functions.php:

add_filter( "link_to_existing_content_post_types", "my_link_to_existing_content_post_types" );
function my_link_to_existing_content_post_types( $post_types ) {  
    $post_types = array( "post", "page" );
    return $post_types;
}

This plugin also has the functionality to replace internal links with shortcodes. If you don't want to use this, deactivate it like this:

add_filter( "link_to_existing_content_use_shortcode", "disable_link_to_existing_content_shortcode" );
function disable_link_to_existing_content_shortcode() {
    return false;
}

Full instructions can be found here: https://wordpress.org/plugins/b09-link-to-existing-content/faq/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.